Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Use faster globs for template resolving #33860
Its search is mostly equivalent to:
This is relatively slow. Ruby will check the existance of each possible file:
For the example above, which is not the worst - variants and fallback locales would add to complexity, that's 2 * 35 * 6 = 420 checks. Not nice.
Each of these checks needs 4 syscalls (it checks each path up the tree), resulting in 1682 syscalls. This would be even worse in a real app because it scans an absolute path.
It's much faster, as proposed in #20752 to scan the directory with a wildcard, and then filter the results in Ruby.
This is only 14 syscalls. Great!
Filtering this would be trivial using the existing glob and
Although Ruby's docs don't guarantee an order returned by
This PR solves this by also building a regex to match paths and then using it to both ensure each file actually matches (vs just shares the prefix) and extract the details values which were matched. We then use the matched values to sort the results into the same order they would have been returned by the original glob pattern.
Thanks for reading
I'm not familiar with the release system on Rails. Checking the documentation, I can read this:
Will this be back-ported? Or it won't be for the next major, but rather a minor?
Edit: Great job @jhawthorn, thank you for your contribution!
@rafaelfranca : Which versions of Rails would accept this back-port? I'm interested in getting this into 4.2, 5.0, and 5.1. I did some searching, but couldn't find the policy around back-porting.
@jeremy : Thanks. I guess based on the Maintenance Policy, a performance optimization mainly for development mode would be categorized under "Bug Fixes" at best.
Is the Rails team interested in a PR for Rails 5.2?
Also, any chance a back-port for Rails 5.0 or 5.1 would be accepted?