Skip to content

Engine: Compute the project path lazily - #2310

Merged
marcoroth merged 1 commit into
mainfrom
engine/lazy-project-path
Aug 20, 2026
Merged

Engine: Compute the project path lazily#2310
marcoroth merged 1 commit into
mainfrom
engine/lazy-project-path

Conversation

@marcoroth

Copy link
Copy Markdown
Owner

This pull request stops VisitorContext from asking the operating system where it is for every template it builds a context for.

coerce_project_path falls back to Pathname.new(Dir.pwd) when no project path is given, and it ran during construction. The project path is only read when a visitor, a diagnostic, an overlay or the relative file path asks for it, so a template compiled without any of those still paid for a getcwd and two allocations.

Deriving it on demand takes about 7% off compile time over the examples/ corpus.

The value is unchanged. coerce_project_path keeps its behavior for a caller that passes a path, and the derived one is cached through the same mutable holder #2262 introduced for the relative file path, so the context can stay frozen.

Follow-up to #2262.

@marcoroth marcoroth added optimization Compile-time and generated-output optimizations performance Speed and memory usage improvements labels Aug 20, 2026
@github-actions github-actions Bot added ruby Ruby source for the gem and its libraries rbs RBS type signatures in sig/ engine Herb engine and Rails template compilation rubygem The herb RubyGem and its packaging labels Aug 20, 2026
@nx-cloud

nx-cloud Bot commented Aug 20, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit b79c119

Command Status Duration Result
nx run-many -t test --all --parallel --exclude=... ✅ Succeeded 2m 50s View ↗
nx run-many -t build --all --exclude=herb-langu... ✅ Succeeded 15s View ↗
nx build @herb-tools/tailwind-class-sorter ✅ Succeeded 1s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-08-20 04:13:27 UTC

This pull request stops `VisitorContext` from asking the operating system
where it is for every template it builds a context for.

`coerce_project_path` falls back to `Pathname.new(Dir.pwd)` when no project
path is given, and it ran during construction. The project path is only
read when a visitor, a diagnostic, an overlay or the relative file path
asks for it, so a template compiled without any of those still paid for a
`getcwd` and two allocations.

Deriving it on demand takes about 7% off compile time over the `examples/`
corpus, measured A/B interleaved against `main`.

The value is unchanged. `coerce_project_path` keeps its behavior for a
caller that passes a path, and the derived one is cached through the same
mutable holder #2262 introduced for the relative file path, so the context
can stay frozen.

Follow-up to #2262, which left this the last eagerly computed field on the
context.
@github-actions

github-actions Bot commented Aug 20, 2026

Copy link
Copy Markdown

🌿 Interactive Playground and Documentation Preview

A preview deployment has been built for this pull request. Try out the changes live in the interactive playground:


🌱 Grown from commit 1cb3115


✅ Preview deployment has been cleaned up.

@pkg-pr-new

pkg-pr-new Bot commented Aug 20, 2026

Copy link
Copy Markdown
@herb-tools/client

npx https://pkg.pr.new/@herb-tools/client@2310

@herb-tools/core

npx https://pkg.pr.new/@herb-tools/core@2310

@herb-tools/dev-tools

npx https://pkg.pr.new/@herb-tools/dev-tools@2310

@herb-tools/formatter

npx https://pkg.pr.new/@herb-tools/formatter@2310

@herb-tools/language-server

npx https://pkg.pr.new/@herb-tools/language-server@2310

@herb-tools/linter

npx https://pkg.pr.new/@herb-tools/linter@2310

commit: 1cb3115

@marcoroth
marcoroth merged commit 7632ea5 into main Aug 20, 2026
35 checks passed
@marcoroth
marcoroth deleted the engine/lazy-project-path branch August 20, 2026 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

engine Herb engine and Rails template compilation optimization Compile-time and generated-output optimizations performance Speed and memory usage improvements rbs RBS type signatures in sig/ ruby Ruby source for the gem and its libraries rubygem The herb RubyGem and its packaging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant