-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Speed up rbenv by dynamically loading compiled command #528
Conversation
This file contains 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
On systems that support both C compiling and dynamic loading, we can speed up `realpath()` (where most time in rbenv is spent) by replacing it with a dynamically loaded bash builtin. When `make -C src` is called in the project's root, `libexec/rbenv-realpath.dylib` will be created. If it exists, rbenv will attempt to load it as a builtin command. If it fails, execution will fall back to the old `realpath()` shell function.
With `realpath` extension, hooks tests on OS X will output `/private/tmp` instead of `/tmp` because the latter is an actual symlink to the former. Avoid this mistmach in output assertions by expanding BATS_TMPDIR if `realpath` extension is compiled.
This speeds up every `rbenv` invocation significantly.
It's slow and not necessary since we expect `$0` to already be expanded. In tests this change forces us to deal with some relative paths, but it's not a big deal. The `rbenv init -` output in the most common case will be the same as before: source '/home/myuser/.rbenv/libexec/../completions/rbenv.bash'
Seems to only work on OS X; fails on Travis https://travis-ci.org/sstephenson/rbenv/jobs/16384866
Given the `-o <HOST-OS>` parameter, the script generates environment variables with information how to compile dynamically loadable libraries for that system. Imported from bash-3.2.48
The `shobj-conf` script imported from bash seems to not support the latest OS X. This makes sure that `SHOBJ_LDFLAG=-dynamiclib` is output for Darwin10+ (latest version is Darwin 13.0).
The previous Makefile only worked on OS X. The dynamically generated Makefile (from `Makefile.in`) should now work on multiple platforms (tested on OS X and Ubuntu).
mislav
added a commit
that referenced
this pull request
Oct 15, 2014
Speed up rbenv by dynamically loading compiled command
Nice! |
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.
The most time spent in rbenv execution is resolving paths to their absolute representations without symlinks. Manually doing this in bash is slow.
By dynamically loading a compiled bash builtin, we can access the
realpath
POSIX C function which does exactly what we need and is fast.If dynamic loading fails, rbenv will still continue working as before (will fall back to shell implementation).
If RBENV_NATIVE_EXT environment variable is set, rbenv will abort if it didn't manage to load the builtin. This is primarily useful for testing.
Tested on OS X 10.9 and Ubuntu 12.
/cc @sstephenson