Fix caching gaps and reduce Pathname overhead#161
Open
pharris2411 wants to merge 1 commit intorubyatscale:mainfrom
Open
Fix caching gaps and reduce Pathname overhead#161pharris2411 wants to merge 1 commit intorubyatscale:mainfrom
pharris2411 wants to merge 1 commit intorubyatscale:mainfrom
Conversation
Cache nil results in TeamFinder.for_file when RustCodeOwners returns nil, preventing repeated uncached calls to the Rust layer for unowned files. Memoize Pathname.pwd and use string prefix stripping instead of Pathname#relative_path_from for the common case, eliminating costly Pathname allocations and cleanpath operations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TeamFinder.for_filepreviously skipped caching whenRustCodeOwners.for_filereturnednil, causing repeated calls to the Rust layer for every lookup of an unowned file. Now cachesnilso subsequent lookups are instant.Pathname.pwd: The working directory doesn't change during a process, butPathname.pwdwas called on every invocation, issuing a syscall each time. Now memoized inFilePathFinder.pwd.Pathname#relative_path_fromwith string prefix strip: For files under the project root (the common case), we useString#delete_prefixinstead ofPathname.new(path).relative_path_from(pwd), avoiding costlyPathnameallocations,cleanpath, andcleanpath_aggressivechains. Falls back to Pathname for paths outside the project root.Context
Profiling
CodeOwnership.for_filein a large Rails app (Gusto/zenpayroll) showed:Pathname.pwdsyscallsPathname#relative_path_from→cleanpath→File.basenamechainsResults
This is testing with getting 100 instances of code ownership for an unowned job.
Before, this took about 104 ms
After, this takes 1.41 ms
Test plan
🤖 Generated with Claude Code