-
Notifications
You must be signed in to change notification settings - Fork 188
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
cache dlsym lookup #2
Conversation
function libpython_name(python::String) | ||
lib = replace(readall(`$python -c "import distutils.sysconfig; print distutils.sysconfig.get_config_var('LDLIBRARY')"`), | ||
r"\.so(\.[0-9\.]+)?\s*$|\.dll\s*$", "", 1) | ||
@osx_only if lib[1] != '/'; lib = "/System/Library/Frameworks/"*chomp(lib) end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this fixes a separate issue where Mac seems to always return a relative path that should be prefixed by /System/Library/Frameworks
@vtjnash, sorry I didn't notice this earlier. How much of a performance difference does this make? e.g. on a simple benchmark like |
Hmm, looks like it makes a big difference:
A factor of 100 may be worth caching for... |
i figured. a dictionary lookup is not as fast as a constant reference. (as a side note, the type assertion on the first argument of the ccall is unnecessary -- it should generate nearly the same code, but accept any Ptr{T}}) i tried merging this forward, but it was tricky since this doesn't check that the symbol it receives is actually constant and just blindly caches the value regardless which can cause some surprises |
In all the places where the argument to |
that sounds even better. i wasn't certain if it needed to be a runtime value somewhere, so i was trying to just propagate the macro calls outward (almost as a primitive form of inlining) |
Your type annotation |
were you able to characterize the performance impact of this approach in actual code? |
No, I didn't try anything except for the synthetic benchmark above. (I suspect that in most realistic circumstances the overhead of the |
I didn't do a test for whether this actually makes a significant difference in speed, but I wanted to see whether and how this would work (I'm not certain if it is actually better)
(note: there should probably be a type assert that
func
is actually a Symbol, otherwise we cache the result of a dynamic variable)