JuliaPhysics / JuliaPhysics/Unitful.jl
100x Performance regression with @fastmath in combination of two units with different types (Float and Int)
- Dominant language
- Julia
- Stars
- 675
- Forks
- 124
- Avg merge
- 3h 38m
- Merged PRs (30d)
- 1
Description
Here is MWE:
```julia
import Unitful: Hz, MHz
function accumulate_phase(f0, fs)
phase_accu = 0.0
@fastmath for i = 1:4000
phase_accu += f0 * i / fs
end
phase_accu
end
```
```julia
julia> @btime accumulate_phase($(100.23Hz), $(4MHz))
249.836 μs (0 allocations: 0 bytes)
200.510115
julia> @btime accumulate_phase($(100.23Hz), $(4e6Hz))
2.792 μs (0 allocations: 0 bytes)
200.51011499999998
julia> @btime accumulate_phase($(100Hz), $(4MHz))
3.303 μs (0 allocations: 0 bytes)
200.05
```
That is **249.836 μs** against 2.792 μs
Without fastmath:
```julia
function accumulate_phase_wo_fastmath(f0, fs)
phase_accu = 0.0
for i = 1:4000
phase_accu += f0 * i / fs
end
phase_accu
end
```
```julia
julia> @btime accumulate_phase_wo_fastmath($(100.23Hz), $(4MHz))
4.489 μs (0 allocations: 0 bytes)
200.510115
julia> @btime accumulate_phase_wo_fastmath($(100.23Hz), $(4e6Hz))
4.458 μs (0 allocations: 0 bytes)
200.510115
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the issue with the accumulate_phase and accumulate_phase_wo_fastmath examples using Julia's @btime measurements. Compare the mixed Float and Int unit cases with the Float-only and non-@fastmath cases; done means eliminating the severe regression while preserving the reported numerical results and zero-allocation behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100