←back to thread

83 points hyperbrainer | 1 comments | | HN request time: 0s | source
Show context
rbjorklin ◴[] No.43965319[source]
Does anyone have some hard numbers on the expected performance uplift when using GADTs? Couldn't see any mentioned in the article.
replies(1): >>43965690 #
ackfoobar ◴[] No.43965690[source]
The example here is basically an 8-fold memory saving going from `long[]` from `byte[]` - while still retaining polymorphism (whereas in Java the two are unrelated types).

Hard to say exactly how much performance one would get, as that depends on access patterns.

replies(1): >>43966244 #
misja111 ◴[] No.43966244[source]
The reason that a byte array is in reality layed out as a (mostly empty) long array in Java, is actually for performance. Computers tend to have their memory aligned at 8 byte intervals and accessing such an address is faster than accessing an address that's at an offset of an 8 byte interval.

Of course it depends on your use case, in some cases a compact byte array performs better anyway, for instance because now you're able to fit it in your CPU cache.

replies(2): >>43966389 #>>43966582 #
1. john-h-k ◴[] No.43966389{3}[source]
But you can load any byte by loading 8 bytes and shift (v cheap)