FasterPath: Faster Pathname Handling for Ruby Written in Rust
github.com
github.com
My solution after years of agony has been to just throw it all out, and use a diff asset packager underneath rails.
Really happy that people are taking this issue on. Wish I had the time to help out.
FasterPath Rust Implementation Ruby 2.3.1 Implementation Performance Improvement
FasterPath.absolute? Pathname#absolute? 1234.6%
Nothing like getting 3 orders of magnitude performance improvement.If I change it to just check the first character for the file separator, as I understand FasterPath does, then of course it is faster:
Warming up --------------------------------------
original 4.109k i/100ms
faster 110.202k i/100ms
Calculating -------------------------------------
original 42.645k (± 3.7%) i/s - 213.668k in 5.017595s
faster 2.643M (± 4.4%) i/s - 13.224M in 5.013294s
Comparison:
faster: 2643274.6 i/s
original: 42644.5 i/s - 61.98x slower
My implementation: class Pathname
def f_relative?
@path[0] != File::SEPARATOR
end
end
[1] https://github.com/ruby/ruby/blob/68ebbbfebe5b666cf76ab41f1e...[1] https://github.com/ruby/ruby/blob/68ebbbfebe5b666cf76ab41f1e...
There are a ton of edge cases in path manipulation code.
Edit: changed link to blob version which will not change line numbers on me.
r_str.chars().next() == Some(MAIN_SEPARATOR)
Definitely not the clearest way to do that.