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.
This PR provides an alternative implementation for a long → decimal conversion.
The main difference is that it uses an algorithm pulled from https://github.com/jeaiii/itoa. The source there is C++, it was converted by hand to C for inclusion with this gem. A writeup of this algorithm can be found here. jeaiii's algorithm is covered by the MIT License, see source code.
On addition this version now also generates the string directly into the
fbuffer
, foregoing the need to run a separate memory copy.As a result, I see a speedup of 32% on Apple Silicon M1 for an integer set of benchmarks.
These benchmarks are run via a script (link) which is based on the gem's
benchmark/encoder.rb
file. There are probably better ways to run benchmarks :) My version allows to combine multiple test cases into a single one.The script adds a "cents" test case (link) which explicitly covers integers in a range that is relevant for financial institutions. (Comparing benchmarks for that case show a speedup of 41%)
The
dumps
benchmark, which covers the JSON files inbenchmark/data/*.json
, sees a speedup of ~8 %.