simd-json icon indicating copy to clipboard operation
simd-json copied to clipboard

runtime dispatch and other goodies from upstream

Open sunnygleason opened this issue 5 years ago • 9 comments

One idea we should consider soonish is compiling everything for the target architecture regardless of CPU features and doing runtime detection & dispatch (as implemented in upstream, hopefully easier in Rust?).

There might be other goodies in upstream as well...

sunnygleason avatar Feb 07 '20 22:02 sunnygleason

I got no idea how that'd work in rust but that just means we got to learn something new :D

Licenser avatar Feb 07 '20 22:02 Licenser

I’ll have a go at this. @Licenser can you assign this to me 😄 ?

CJP10 avatar Oct 21 '20 14:10 CJP10

Thanks @CJP10 go for it :)

Licenser avatar Oct 21 '20 14:10 Licenser

I got no idea how that'd work in rust but that just means we got to learn something new :D

From what I understand you use something like is_x86_feature_detected!("ssse3") to detect whether a particular feature is available. Then you call a function optimized for that feature. You have to mark the function with #[target_feature(enable = "ssse3")] to force usage of that feature within the function.

Here an example and another one.

AndreKR avatar Oct 21 '20 20:10 AndreKR

@AndreKR upstream does something similar to ifunc.

CJP10 avatar Oct 21 '20 22:10 CJP10

Ja, we probably want something resembling the upstream solution that does only once include a conditional and after that memorizes the choice.

Licenser avatar Oct 22 '20 07:10 Licenser

To add, we should also have a simd_json::init(). Which would be optional but perform the runtime selection outside of the hot path.

CJP10 avatar Oct 22 '20 17:10 CJP10

Yes very good idea 👍 that way applications who want to make sure there is 0 overhead on the hot path can call it on startup :), good thinking!

Licenser avatar Oct 22 '20 17:10 Licenser

Maybe take some inspiration from rust-memchr: ifunc-like macro for Rust

Count-Count avatar Oct 30 '20 08:10 Count-Count