JuliaMath / JuliaMath/FixedPointNumbers.jl
Reducing the definitions of the `floor`, `ceil`, and `trunc` methods to mitigate invalidation
- Dominant language
- Julia
- Stars
- 95
- Forks
- 38
- Avg merge
- 13m
- Merged PRs (30d)
- 2
Description
At least as of julia v1.0, `floor(x)` has fallen back to `round(x, RoundDown)`.
Starting with julia v1.11, `floor(T, x)` has also been made to fall back to `round(T, x, RoundDown)`.(cf. https://github.com/JuliaLang/julia/pull/45598)
Therefore, it should be sufficient to define only `round(x, ::RoundingMode)` and `round(T, x, ::RoundingMode)` in FPN.
Conversely, starting with Julia v1.11, defining methods such as `floor(T, x)` may carry a higher risk of invalidation.
(As efforts related to TTFX within the Julia ecosystem are also advancing, it is unclear what impact this will have on actual performance.)
Of course, invalidation triggered by the 2-/3-arg `round` is, in principle, unavoidable.
However, I think it can be effective if the invalidation results from the casual (type-instable) use of functions like `floor`.
Since rounding functions like `floor` are expected to be inlined when there is no risk of overflow/underflow (e.g., `ceil(typemax(Q0f7))`), I don't think there will be much of a performance penalty.
It’s fragile against piracy and future changes to `Base` implementation, but I’m sure someone will notice and fix it.
Contributor guide
Research direction
Locate the FPN definitions of floor, ceil, trunc, and round, then compare their behavior with Julia 1.11's fallback methods. The work is done when the redundant definitions are reduced without changing rounding behavior and the existing package checks confirm the result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- performance
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100