This gem replaces most-used Pathname class ruby methods with much faster counterparts written in Nim.
Use for hassle-free, dependency-free speed gains, primarily in Rails projects.
As of version 0.9.0 the gem will support 64bit versions of Linux and Mac.
Support for Windows is a hassle due to differing path separator, among other things.
Open an issue or PR if other OS support is needed.
ruby ">= 2.1.10" # for required keyword arguments
gem 'nimbler_path', require: false
# in an initializer like /config/initializers/nimbler_path.rb
require 'nimbler_path'
require 'nimbler_path/monkeypatch'
NimblerPath.apply_monkeypatch!(verbose: true)
faster_path identifies these Pathname methods as taking the most execution time.
Pathname#chop_basename(path) @ https://goo.gl/9Lk1N9 called 24456 times, 25% of execution time alone
Pathname#to_s (implicit C definition?) called 29172 times.
Pathname#<=> (implicit C definition?) called 24963 times.
Pathname#initialize in C @ https://goo.gl/dqB8R2 called 23103 times.
Pathname#absolute? @ https://goo.gl/5aXYxw called 4840 times.
Pathname#+ @ https://goo.gl/W7biJu called 4606 times.
Pathname#plus @ https://goo.gl/eRxLYt called 4606 times.
Pathname#join @ https://goo.gl/9NzWRt called 4600 times.
Pathname#extname in C @ https://goo.gl/uANaNu called 4291 times.
Pathname#hash in C @ https://goo.gl/6eVS1x called 4207 times.
Pathname#to_path in C @ https://goo.gl/EX7Cfx called 2706 times.
Pathname#directory? in C @ https://goo.gl/PbMbjY called 2396 times.
Pathname#entries in C @ https://goo.gl/8ALU6R called 966 times.
Ignoring methods already implemented in C leaves us with:
Pathname#chop_basename(path) @ https://goo.gl/9Lk1N9 called 24456 times, 25% of execution time alone
Pathname#+ @ https://goo.gl/W7biJu called 4606 times.
Pathname#plus @ https://goo.gl/eRxLYt called 4606 times.
Pathname#join @ https://goo.gl/9NzWRt called 4600 times.
Pathname#absolute? @ https://goo.gl/5aXYxw called 4840 times.
# flipside
Pathname#relative? @ https://goo.gl/QK4PCs
This project, at most, aims to provide performant variants for those six methods.
Bug reports and pull requests are welcome on GitHub at https://github.com/Epigene/nimbler_path. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
Ruby development setup
- Clone the project with
git clone [email protected]:Epigene/nimbler-path.git
- Make sure you are using Ruby v2.1.10
- Bundle
- Run naive gem-code tests with
ruby test/nimbler_path_test.rb
- Run the tests in included Ruby Spec Suite with
mspec/bin/mspec spec
(Specs affected by this gem are run withmspec/bin/mspec spec/library/pathname
. - Work on feature, commit and make a pull request 👏
- See how benchmarks add up with
ruby test/nimbler_path_benchmarks.rb
Please note that this project includes a snapshot of the Ruby Spec Suite project under spec
and a snapshot of MSpec project under mspec
.
__Nim development setup
- Make sure you are running nim ..
- See if compilation works ..
- Work on nim code changes..
- https://forum.nim-lang.org/t/3153
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the NimblerPath project’s codebases and issue trackers is expected to follow the code of conduct.