Skip to content

Conversation

@kozross
Copy link
Contributor

@kozross kozross commented Nov 20, 2025

This optimizes the conversions between Integer and ByteString, as we can now rely on Integer internals, which lets us use direct copying instead of digit-by-digit extraction and reconstruction.

I did not changelog this, as this change is designed to be invisible at the API level. This will require these operations to be re-costed, as this change means we should see an algorithmic improvement (from $\Theta(n^2)$ to $\Theta(n)$ ).

@basetunnel basetunnel requested a review from kwxm November 21, 2025 13:00
@zliu41 zliu41 requested a review from a team December 5, 2025 01:44
Copy link
Member

@zliu41 zliu41 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite low level stuff, but I've gone through the logic and it all checks out.

LittleEndian -> pure ()
BigEndian -> reverseBuffer ptr desiredLength
goSmallLE :: Ptr Word8 -> Int -> Int# -> IO ()
goSmallLE ptr offset remaining#
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a bang to offset? Ditto for all other Int arguments.

copyByteArrayToAddr ptr (ByteArray ba#) 0 minLength
case requestedByteOrder of
LittleEndian -> pure ()
BigEndian -> reverseBuffer ptr desiredLength
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any idea how much overhead reverseBuffer has?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants