News for hackers. Stuff that matters.
Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by ekidd on Friday June 17, 2016 @11:01AM (#11923010)
Articles like this one, and the recent project on libraries like Helix http://blog.skylight.io/introducing-helix/ make me awfully tempted to rewrite inner loops in certain production Ruby projects in Rust.
Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by bjourne on Friday June 17, 2016 @02:31PM (#11924561)
How on earth can pathname handling be a performance drag? If I read his stats correctly, then `Pathname#chop_basename` is called 24456 times for one page load. Something is very fishy about that.
Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by viraptor on Friday June 17, 2016 @05:10PM (#11925573)
Agree, and that's per actual page load. Not at the start of the app. If there's no dynamic searching for paths in the app, I don't understand why there would be even one path operation done after the first request. Templates, extra resources, etc. - you can optimise this down to assembler, but it's always going to take time. What solves this is just caching the results - you don't run the path operations anymore.
Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by ape4 on Friday June 17, 2016 @05:58PM (#11925809)
Exactly what I was thinking. You look for the last slash and truncate.
Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by ugexe on Friday June 17, 2016 @07:18PM (#11926131)
This is a naive solution. Try using that on windows.
Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by ajmurmann on Friday June 17, 2016 @08:23PM (#11926359)
This actually makes me wonder if it would be worthwhile to look for this and similar issues and remove Windows support from the methods for a custom implementation. It might shave off some more time.
Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by ape4 on Friday June 17, 2016 @09:31PM (#11926560)
Still, use a pattern to find the last slash or backslash. Should be pretty quick.
Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by jacquesc on Friday June 17, 2016 @11:23AM (#11923168)
Rails is such a huge community, and Sprockets has to be one of the biggest pain points for many years.

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.

Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by drewda on Friday June 17, 2016 @11:52AM (#11923350)
Re Sprockets, I found this recent talk at RailsConf about the history, problems, and future of Sprockets maintenance and development to be an interesting read: http://schneems.com/2016/05/31/saving-sprockets.html
Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by 33degrees on Friday June 17, 2016 @11:41AM (#11923285)
Given how much modern js development depends on node and npm, I think using a different asset packager is the most sensible way to go.
Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by vvanders on Friday June 17, 2016 @01:30PM (#11924084)

  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.
Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by InAnEmergency on Friday June 17, 2016 @01:43PM (#11924204)
Ruby's `Pathname#absolute?` is doing a lot more work[1]. I don't know why, but it is.

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...
Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by 33degrees on Friday June 17, 2016 @02:22PM (#11924481)
A quick look at the tests[1] shows that it handles drive letters. The current implementation is probably not the most efficient though...

[1] https://github.com/ruby/ruby/blob/68ebbbfebe5b666cf76ab41f1e...

Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by munificent on Friday June 17, 2016 @02:48PM (#11924719)
That returns a wrong result on Windows paths, and throws an exception on the empty string.

There are a ton of edge cases in path manipulation code.

Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by kevincox on Friday June 17, 2016 @04:49PM (#11925456)
I'm pretty sure his implementation works on empty strings because `str[0].nil?`. So the comparison is false, giving the right (?) answer.
Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by idbehold on Friday June 17, 2016 @12:04PM (#11923434)
I'm not at all familiar with programming in Rust or Ruby, but what is the significance of the string "muffins" on this line? https://github.com/danielpclark/faster_path/blob/7033f5a5673...

Edit: changed link to blob version which will not change line numbers on me.

Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by nilved on Friday June 17, 2016 @12:20PM (#11923558)
I don't write Rust either, but I might guess that they are trying to unbox a nullable value that can't be null. They need a default string due to Rusts strong types even if it's not used.
Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by gue5t on Friday June 17, 2016 @12:31PM (#11923616)
A more idiomatic way to write the line is:

r_str.chars().next() == Some(MAIN_SEPARATOR)

Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by jason_dstillery on Friday June 17, 2016 @01:20PM (#11923981)
It's a string whose first character is guaranteed not to match MAIN_SEPARATOR, so that the expression always returns false when r_str is empty.

Definitely not the clearest way to do that.

Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by Sarkie on Friday June 17, 2016 @12:09PM (#11923465)
Not a clue. http://www.rubydoc.info/gems/muffins/0.0.6 Maybe? Hilarious find though.
Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by blacksmith_tb on Friday June 17, 2016 @12:08PM (#11923461)
I haven't worked with Rust myself, but I read that as a failover/rescue, to provide a string for debugging purposes (hence the silliness).
Re:FasterPath: Faster Pathname Handling for Ruby Written in ... by wofo on Friday June 17, 2016 @08:01AM (#11922096)
Not the OP. Just found this very interesting.