3 ms·
Yeah it's pretty bad, but Jane Street is working on adding unboxed types.
by Ericson2314 3y ago
Yeah it's pretty bad, but Jane Street is working on adding unboxed types.
- mkristiansen 3y agoAnd to be honest, this might be the sorta thing that is optimized away when doing inlining. but it does seem interesting that even when the type is species, and very narrow, the boxed types being onwrapped and rewrapped by the called function, rather than the caller. As a side note it took me a second to realize that the multiplication being done is not actually xx, but rather (x (x<<1))
- zem 3y agoif anyone hasn't delved into why, it's because the ocaml integer `x` is represented by the machine integer `(2x + 1)`. so what `x * x` compiles to is `((2x + 1) - 1) * ((2x + 1) / 2) + 1` which is `2x * x + 1` = `2(x * x) + 1`, or the machine integer representing the ocaml integer `(x * x)`.
- tempodox 3y agoTo be precise, it's x * (x << 1) + 1. You need to set bit 0 to signal to the garbage collection that this is not a heap box.
- c-cube 3y agoIs it really bad? In the grand scheme of things this should have little impact. No branches. The pipeline will do these extra ops really fast. A bigger problem with perf in ocaml is the amount of indirection and the subsequent cache misses, which can amount to hundreds of cycles.
- Ericson2314 3y agoThe amount of indirection is the same problem as this. This is just a tiny example of it.