Skip to content

Conversation

@domingo2000
Copy link
Contributor

@domingo2000 domingo2000 commented Aug 30, 2025

By doing a walk over the tree of directories in the workpsace we improve the dir Glob time because it only checks for the closest test directory folder, instead of searching in all the files of the workspace.

Motivation

Closes #3327

Implementation

As discussed here the implementation consist in a tree walk over the directory structure. By doing this walk until the workspace path, we only check for test files in the most closer ancestor folder that contains tests, the locality of tests in projects using engines in rails, or Packwerck, or in general in ruby projects, make the search correct most of the times.

By checking fewer directories the performance of the Glob that search for files is improved drastically, making the go to relevant file feels instant in big projects.

Automated Tests

Changed the current test implementation to use tempdirs and create some examples in that tempdir. That way the tests are not implementation specific, as it was when stubbing the filesystem calls.

Manual Tests

  1. Rubocop project
screenrecording-2025-08-30_16-11-24.mp4
  1. Rails project
screenrecording-2025-08-30_16-15-06.mp4
  1. Buk Core project (> 27K ruby files)
screenrecording-2025-08-30_16-14-19.mp4

@domingo2000 domingo2000 requested a review from a team as a code owner August 30, 2025 20:16
@graphite-app
Copy link

graphite-app bot commented Aug 30, 2025

How to use the Graphite Merge Queue

Add the label graphite-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

Copy link
Contributor

@jenny-codes jenny-codes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea but left some comments!

@domingo2000 domingo2000 force-pushed the improve-go-to-relevant-file-performance branch from 3041894 to 5d0e220 Compare October 1, 2025 17:47
@domingo2000
Copy link
Contributor Author

domingo2000 commented Oct 1, 2025

Thanks for the feedback @jenny-codes! I corrected all revisions, If you have any more feedback let me know.

Also checked again manually on the rubocop, rails and Buk monorepo to be sure it works well 👍🏻 .

@domingo2000 domingo2000 force-pushed the improve-go-to-relevant-file-performance branch from 5d0e220 to ed632b0 Compare October 2, 2025 21:20
@domingo2000
Copy link
Contributor Author

I changed to the relative path implementation. It works fine with manual testing. I will try to change the test to use a fixture folder in the filesystem instead of stubbing the responses to test the implementation without harcoding it.

@domingo2000 domingo2000 force-pushed the improve-go-to-relevant-file-performance branch 3 times, most recently from ddf2ae5 to fc31e36 Compare October 3, 2025 12:32
@domingo2000
Copy link
Contributor Author

@jenny-codes I ended up testing the feature using a temporary directory strategy. That way the stubs are not implementation specific, the test is autocontained, and we don't need a real fixture folder.

@domingo2000 domingo2000 force-pushed the improve-go-to-relevant-file-performance branch from fc31e36 to a30f4dd Compare October 3, 2025 12:50
@jenny-codes jenny-codes added enhancement New feature or request server This pull request should be included in the server gem's release notes labels Oct 14, 2025 — with Graphite App
Copy link
Contributor

@jenny-codes jenny-codes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update! The implementation looks good but I wonder if it'd be worth it to add a test that verifies that we will search only within the "search root". We can make a test where we have this file structure

root
- a
   - test 
      - implementation_test.rb
   - implementation.rb
- b
   - test 
      - implementation_test.rb
   - implementation.rb

and assert that we don't return the implementation <> test results for a in b.

By doing a walk over the tree of directories in the workpsace we improve
the dir Glob time because it only checks for the closest test directory
folder, instead of searching in all the files of the workspace.
@domingo2000 domingo2000 force-pushed the improve-go-to-relevant-file-performance branch from a30f4dd to 81658a2 Compare October 15, 2025 20:25
@domingo2000
Copy link
Contributor Author

@jenny-codes, changed the test to only create the files, and added the "test within root" test to check that we don't get tests outside the search root.

Copy link
Contributor

@jenny-codes jenny-codes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thank you!

@domingo2000
Copy link
Contributor Author

@jenny-codes I have no permissions to merge to shopify upstream, just pinging in case you forgot, no hurry on this PR.

@jenny-codes jenny-codes merged commit 0c4d46c into Shopify:main Oct 17, 2025
22 checks passed
@Shopify Shopify deleted a comment from graphite-app bot Oct 17, 2025
@jenny-codes
Copy link
Contributor

@domingo2000 thank you!

@domingo2000
Copy link
Contributor Author

Thank to you!, I really use this feature a lot, and have used a lot your initial implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request server This pull request should be included in the server gem's release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve GoToRelevantFile performance

2 participants