amazon-ion / ion-docs

Source for the GitHub Pages for Ion.
https://amazon-ion.github.io/ion-docs/
Apache License 2.0
22 stars 22 forks source link

Evaluate whether switching `float` to little endian in Ion 1.1 is worthwhile #294

Closed zslayton closed 2 months ago

zslayton commented 6 months ago

Our int encodings (including primitives) have switched to little endian in Ion 1.1 for a performance boost. Floats also rely on the CPU's native endianness, but the current version of the spec leaves them big endian.

zslayton commented 6 months ago

For reference, here's the assembly generated by the conversion to LE bytes and to BE bytes on x86_64:

image

Depending on your perspective, that's either a trivial difference or it's 100% more instructions! 😛

popematt commented 6 months ago

It does look pretty trivial (unless, perhaps, you're encoding lots of floats in a tight loop). We should see if there's a significant performance difference in Java (and maybe some other languages) to make a more informed decision.

zslayton commented 4 months ago

Per team discussion, we're leaning little endian for consistency. Java's ByteBuffer has an API for swapping endianness.

popematt commented 2 months ago

@zslayton, I'm going to close this as completed. Feel free to re-open if you disagree.