version/parser: speed up StemParser#23007
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR removes an unnecessary filesystem I/O check from Version::StemParser to speed up version parsing and avoid parsing behavior depending on whether a matching directory happens to exist on disk.
Changes:
- Remove
spec.directory?short-circuit fromVersion::StemParser.process_spec, eliminating a filesystem stat during parsing. - Remove the unit test that asserted the old “directories are returned as basename” behavior, aligning tests with the new deterministic parsing behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Library/Homebrew/version/parser.rb | Removes the directory existence check in StemParser to avoid I/O and keep parsing purely string-based. |
| Library/Homebrew/test/version/parser_spec.rb | Drops the directory-focused spec that validated the removed behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
daeho-ro
approved these changes
Jul 8, 2026
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.
An I/O operation in a version parser is pretty unusual and, unsurprisingly, does show up in flame graphs when doing a lot of version parsing (though the I/O operation itself isn't too expensive).
The check was added in 355bfc1 but seems obsolete to me after
extnamewas adjusted in 8b5fa68. It seems to have additionally also be handled with a5a1b29.There was a unit test added in a06bd4e that did test the behaviour I am removing but it seems to be very focussed on what
StemParserpreviously did internally rather than what it was intended to do to the broader version parsing system. Indeed the version number actually returned fromVersion.parseon that test sample remains the same even with the specialStemParserlogic removed.Removing the directory check should also avoid the scenario where version parsing behaved differently if you happen to have a directory in your PWD that matches the input to the parser.
For this change I did the following:
and did not find any changes between the outputs with and without this change.
brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?