https://github.com/melonedo/singledispatcharrays.jl
Fast single dispatch for arrays of non-homogeneous elements.
https://github.com/melonedo/singledispatcharrays.jl
julia performance
Last synced: over 1 year ago
JSON representation
Fast single dispatch for arrays of non-homogeneous elements.
- Host: GitHub
- URL: https://github.com/melonedo/singledispatcharrays.jl
- Owner: melonedo
- License: mit
- Created: 2021-07-08T11:35:13.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-07-08T15:36:07.000Z (almost 5 years ago)
- Last Synced: 2025-01-26T19:37:14.261Z (over 1 year ago)
- Topics: julia, performance
- Language: Julia
- Homepage:
- Size: 5.86 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SingleDispatchArrays.jl
Fast single dispatch for an array of non-homogeneous elements.
See discussions at [Union splitting vs C++](https://discourse.julialang.org/t/union-splitting-vs-c/61772/20). Because dynamic dispatch is a complicated search in Julia, where it is only a function pointer in C++, Julia has very bad performance with non-homogeneous array relative to C++. This performance drawback can be addressed by either manual or automatic union splitting or "switch-case", equivalently. SingleDispatchArrays.jl implements union splitting with generated function, with manual bookkeeping of possible subtypes.
Benchmark on x86 cloud server:
```
> cd benchmark
> g++ -o lines -O3 -march=native -W -Wall lines.cpp && ./lines
n = 1000000
dynamic dispatch : 0.012808 us per iteration (12.808000 ms total) [500006.610053]
> julia --project=.. lines.jl
result = 500261.127245642
with runtime dispatch: 153.494 ms (2000000 allocations: 30.52 MiB)
with splitting: 8.007 ms (0 allocations: 0 bytes)
with SingleDispatchArrays.jl: 9.075 ms (2 allocations: 32 bytes)
```
The result is common among my x86 machines, but on my Raspberry Pi 4B, the result is 10ms for splitting, 20ms for SingleDispatchArrays.jl and C++.