Skip to content
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

dynamic switching between safe and unsafe FFI #29

Open
claudeha opened this issue Dec 20, 2017 · 1 comment
Open

dynamic switching between safe and unsafe FFI #29

claudeha opened this issue Dec 20, 2017 · 1 comment

Comments

@claudeha
Copy link
Collaborator

Unsafe FFI is faster but calls longer than about 10µs should be avoided as they can block GC, stopping the world in the threaded runtime.

The Numeric.MPFR.Raw module currently reexports Numeric.MPFR.Raw.Safe with safe ccall imports, but it could estimate the cost at runtime (using functions of precision as heuristics) and do an unsafe call if it's likely to complete in time. The heuristics must be cheaper than the overheads of a safe FFI call (which is how much?), otherwise it would be better to just do safe FFI calls all the time.

@cartazio
Copy link

the branching logic should be roughly only a few nanoseconds overhead tops, maybe 20-30ns? probably depends on how the branches get laid out, and i do think perf sensitive math which takes under 100ns will likely not be a user of rounded? branch prediction will likely help, and if we could arrange the check to have the initial "unsafe" route be the pipelined one, the overhead of doing the safe style call would dominate that branch prediction failure (at least when branch prediction isn't firing correclty)

so i think the overhead of the compare against estimated flops count and branch which ffi call shouldn't be that bad, unless somehow instruction cache stuff differs somehow? theres probably some good experiments to be done here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants