Skip to content

SIMD runtime detection refactor#1

Merged
samyron merged 7 commits into
arm-neon-simdfrom
simd-runtime-detection
Jan 21, 2025
Merged

SIMD runtime detection refactor#1
samyron merged 7 commits into
arm-neon-simdfrom
simd-runtime-detection

Conversation

@samyron

@samyron samyron commented Jan 20, 2025

Copy link
Copy Markdown
Owner

Work In Progress

NOTE Still a lot of refactoring left to do.

Refactor to use runtime detection of the best algorithm.

Running under the Windows Subsystem for Linux on a Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz 2.59 GHz

== Encoding long string (124001 bytes)
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]
Warming up --------------------------------------
                json     3.297k i/100ms
                  oj   881.000 i/100ms
Calculating -------------------------------------
                json     32.561k (± 6.0%) i/s   (30.71 μs/i) -    164.850k in   5.085033s
                  oj      8.862k (± 2.5%) i/s  (112.84 μs/i) -     44.931k in   5.073251s

Comparison:
                json:    32560.8 i/s
                  oj:     8862.3 i/s - 3.67x  slower
== Encoding mixed utf8 (5003001 bytes)
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]
Warming up --------------------------------------
                json   102.000 i/100ms
                  oj    17.000 i/100ms
Calculating -------------------------------------
                json      1.126k (±10.7%) i/s  (888.06 μs/i) -      5.712k in   5.150838s
                  oj    188.422 (± 9.0%) i/s    (5.31 ms/i) -    935.000 in   5.009942s

Comparison:
                json:     1126.1 i/s
                  oj:      188.4 i/s - 5.98x  slower


== Encoding mostly utf8 (5001001 bytes)
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [x86_64-linux]
Warming up --------------------------------------
                json   120.000 i/100ms
                  oj    19.000 i/100ms
Calculating -------------------------------------
                json      1.208k (± 3.0%) i/s  (827.74 μs/i) -      6.120k in   5.070336s
                  oj    187.077 (± 2.7%) i/s    (5.35 ms/i) -    950.000 in   5.081109s

Comparison:
                json:     1208.1 i/s
                  oj:      187.1 i/s - 6.46x  slower

@samyron samyron changed the title Simd runtime detection SIMD runtime detection refactor Jan 20, 2025
Comment thread ext/json/ext/generator/generator.c Outdated
state->buffer_initial_length = FBUFFER_INITIAL_LENGTH_DEFAULT;
// TODO ADD RUNTIME CHECKS HERE?

switch(find_simd_implementation()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could do this in Init_generator, so it's only done once when the gem is required, rather than on every JSON.generate call.

@samyron samyron force-pushed the simd-runtime-detection branch from afd7687 to 4347b8d Compare January 21, 2025 03:26
…of the SIMD implementations. Also added a few tests with more characters to ensure the SIMD implementations are tested.
@samyron samyron merged commit b98ab40 into arm-neon-simd Jan 21, 2025
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

Successfully merging this pull request may close these issues.

2 participants