-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
make "dec" and ryu functions faster and simpler #51273
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
We had some common code in `Ryu.append_c_digits` that can be combined with Base logic for the same thing. But it turns out all of this duplicated code in Ryu seems to just make it run slightly slower in most cases. The old version had many more branches to check, even though often numbers are small, so only the last check is meaningful. But the assumption that it would be faster even if all of them were used also seems to not hold up in practice. Particularly for a function like `append_nine_digits` which unrolls completely, but the complicated version has slightly more data dependencies because of they way it is written. Similarly, we replace `unsafe_copy` with `@inbounds[]`, since this is better for the optimizer, which doesn't need to treat this operation as an unknown reference escape. Lastly, we use the append_nine_digits trick from Ryu to make printing of arbitrary big numbers much faster. ``` julia> @Btime string(typemax(Int128)) 402.345 ns (2 allocations: 120 bytes) # before 151.139 ns (2 allocations: 120 bytes) # after ```
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. |
NHDaly
pushed a commit
that referenced
this pull request
Sep 20, 2023
We had some common code in `Ryu.append_c_digits` that can be combined with Base logic for the same thing. But it turns out all of this duplicated code in Ryu seems to just make it run slightly slower in most cases. The old version had many more branches to check, even though often numbers are small, so only the last check is meaningful. But the assumption that it would be faster even if all of them were used also seems to not hold up in practice. Particularly for a function like `append_nine_digits` which unrolls completely, but the complicated version has slightly more data dependencies because of they way it is written. Similarly, we replace `unsafe_copy` with `@inbounds[]`, since this is better for the optimizer, which doesn't need to treat this operation as an unknown reference escape. Lastly, we use the append_nine_digits trick from Ryu to make printing of arbitrary big numbers much faster. ``` julia> @Btime string(typemax(Int128)) 402.345 ns (2 allocations: 120 bytes) # before 151.139 ns (2 allocations: 120 bytes) # after ```
KristofferC
pushed a commit
that referenced
this pull request
Jan 24, 2024
We had some common code in `Ryu.append_c_digits` that can be combined with Base logic for the same thing. But it turns out all of this duplicated code in Ryu seems to just make it run slightly slower in most cases. The old version had many more branches to check, even though often numbers are small, so only the last check is meaningful. But the assumption that it would be faster even if all of them were used also seems to not hold up in practice. Particularly for a function like `append_nine_digits` which unrolls completely, but the complicated version has slightly more data dependencies because of they way it is written. Similarly, we replace `unsafe_copy` with `@inbounds[]`, since this is better for the optimizer, which doesn't need to treat this operation as an unknown reference escape. Lastly, we use the append_nine_digits trick from Ryu to make printing of arbitrary big numbers much faster. ``` julia> @Btime string(typemax(Int128)) 402.345 ns (2 allocations: 120 bytes) # before 151.139 ns (2 allocations: 120 bytes) # after ``` (cherry picked from commit e9d9314)
KristofferC
added
the
backport 1.10
Change should be backported to the 1.10 release
label
Jan 24, 2024
KristofferC
removed
the
backport 1.10
Change should be backported to the 1.10 release
label
Feb 6, 2024
Drvi
pushed a commit
to RelationalAI/julia
that referenced
this pull request
Jun 7, 2024
We had some common code in `Ryu.append_c_digits` that can be combined with Base logic for the same thing. But it turns out all of this duplicated code in Ryu seems to just make it run slightly slower in most cases. The old version had many more branches to check, even though often numbers are small, so only the last check is meaningful. But the assumption that it would be faster even if all of them were used also seems to not hold up in practice. Particularly for a function like `append_nine_digits` which unrolls completely, but the complicated version has slightly more data dependencies because of they way it is written. Similarly, we replace `unsafe_copy` with `@inbounds[]`, since this is better for the optimizer, which doesn't need to treat this operation as an unknown reference escape. Lastly, we use the append_nine_digits trick from Ryu to make printing of arbitrary big numbers much faster. ``` julia> @Btime string(typemax(Int128)) 402.345 ns (2 allocations: 120 bytes) # before 151.139 ns (2 allocations: 120 bytes) # after ``` (cherry picked from commit e9d9314)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
We had some common code in
Ryu.append_c_digits
that can be combined with Base logic for the same thing. But it turns out all of this duplicated code in Ryu seems to just make it run slightly slower in most cases. The old version had many more branches to check, even though often numbers are small, so only the last check is meaningful. But the assumption that it would be faster even if all of them were used also seems to not hold up in practice. Particularly for a function likeappend_nine_digits
which unrolls completely, but the complicated version has slightly more data dependencies because of they way it is written.Similarly, we replace
unsafe_copy
with@inbounds[]
, since this is better for the optimizer, which doesn't need to treat this operation as an unknown reference escape.Lastly, we use the append_nine_digits trick from Ryu to make printing of arbitrary big numbers much faster.
@nanosoldier
runbenchmarks("io" || "misc" || "problem" || "micro" || "shootout", vs=":master")