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

Thread safety: per-task state rather than per-thread #185

Merged
merged 6 commits into from
Jan 28, 2025

Conversation

stevengj
Copy link
Member

@stevengj stevengj commented Jan 28, 2025

Closes #153.

Only a relatively small slowdown (5–30% for Dec64) for basic arithmetic, so a task-local rounding mode doesn't seem to be a huge concern. OLD CODE:

julia> @btime sum($(rand(Dec64, 1000)));
  45.614 μs (0 allocations: 0 bytes)

julia> @btime sum(n -> d64"0.9999"^n, 1:1000);
  933.454 μs (0 allocations: 0 bytes)

NEW CODE:

julia> @btime sum($(rand(Dec64, 1000)));
  60.292 μs (0 allocations: 0 bytes)

julia> @btime sum(n -> d64"0.9999"^n, 1:1000);
  961.635 μs (0 allocations: 0 bytes)

(The first benchmark should be the worst case, because it is only calling +, which is relatively cheap.)

@stevengj stevengj changed the title More thread safety Thread safety: per-task state rather than per-thread Jan 28, 2025
src/DecFP.jl Outdated Show resolved Hide resolved
src/DecFP.jl Outdated Show resolved Hide resolved
@stevengj
Copy link
Member Author

stevengj commented Jan 28, 2025

For some reason eps(d64"1.0") is allocating now — apparently the escape-analysis on the Ref isn't succeeding?

Other math functions like sin(d64"1.0") that also check the exception flags don't seem to allocate…

Update: fixed, just needed a bit of inlining.

@stevengj stevengj merged commit cec673a into master Jan 28, 2025
9 checks passed
@stevengj stevengj deleted the more_thread_safety branch January 28, 2025 21:00
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.

use per-task (not per-thread) flags, rounding mode, etcetera?
1 participant