3 ms·
Not boxing floating-point values on the heap can be a big deal. I retrofitted NaN boxing into a production Lisp implementation literally in one evening and mor
by kazinator 4y ago
Not boxing floating-point values on the heap can be a big deal.
I retrofitted NaN boxing into a production Lisp implementation literally in one evening and morning, with minimal impact to all the existing code in the implementation that is built around the pointer tagging scheme that existed for 13 years. It's nicely delimited with #if CONFIG_NAN_BOXING.
Accumulator-incrementing loop on pointer tagging:
This is the TXR Lisp interactive listener of TXR 281.
Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
1> (compile-toplevel '(for ((i 1.0) (acc 0.0)) ((< i 100000000.0) acc) ((inc acc i) (inc i))))
#<sys:vm-desc: 188b8d0>
2> (pprof [*1])
malloc bytes: 0
gc heap bytes: 6399999936
total: 6399999936
milliseconds: 5860
4.99999995e15
NaN Boxing:
This is the TXR Lisp interactive listener of TXR 281.
Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
1> (compile-toplevel '(for ((i 1.0) (acc 0.0)) ((< i 100000000.0) acc) ((inc acc i) (inc i))))
#<sys:vm-desc: 24b7dc0>
2> (pprof [*1])
malloc bytes: 0
gc heap bytes: 0
total: 0
milliseconds: 4079
4.99999995e15
The speedup is 43.6% here.
3> (/ (- 5860 4079) 4079)
0.436626624172591
This is not native code. The difference would be more emphasized in native code.
However, code that doesn't do floating-point calculation (or even some that does) will see a small performance penalty due to the more complex access to all values. That is a bummer.
At least users can choose; if you don't care about floating-point, build it with pointer tagging.
- sbf501 4y agoI was referring to the table on their original web page. The last two rows are a 1.5% performance difference.