Skip to content

feat: Cleanup to shrink smallest program size#2389

Open
spotandjake wants to merge 1 commit intograin-lang:oscar/gc-rebasedfrom
spotandjake:spotandjake/smallest-program
Open

feat: Cleanup to shrink smallest program size#2389
spotandjake wants to merge 1 commit intograin-lang:oscar/gc-rebasedfrom
spotandjake:spotandjake/smallest-program

Conversation

@spotandjake
Copy link
Copy Markdown
Member

I wasn't sure if this was a feat or chore. I was looking through the binary of our smallest program, and noticed that a few uneccessairy functions were being left behind. This is a rather small pr that corrects that.

Notably, bigIntToString was using _SIZES, which created a closure in every program. I did some additional optimizations while looking at the function.

  • Remove the unused _SIZES array and closure dependency.
  • Pull out getDigit, which removes a secondary closure and allows us to lazily initialize _DIGITS saving some bytes.
  • Track length with result so we don't need to iterate over the result buffer again. (This also removed a helper function.

The second change was much smaller; we were creating a function in pervasives called setupExceptions. This was being done because previously the exception handling interacted with some unsafe code; however, now it's completely safe, so we can drop the function wrapper, which saves a few bytes.

Just as a note from what I could tell in the binary, our smallest program is pretty well optimized, with most of the remaining code being related to the exception handling setup we do in pervasives. I don't really see much room left to optimize this away, however, beyond determining if exceptions can be thrown in the program and eliminating them at the compiler level.

This work is based on: #2378

This is a rather small pr, I was looking through the binary of our smallest program and noticed a few things that were being left behind.

Not very important but we can save a few bytes by removing the unnecessary function wrapping our exception setup, this function was required when exception handling was unsafe however it's now completely safe so there is no reason to map it.

The bigger change is I noticed that `bigIntToString` was doing some weird things, firstly the `_SIZES` array wasn't actually ever being used however it was causing the function to require a closure which was being setup in every program and adding a rather substantial amount of size. Secondly because we had a helper function that used`_DIGITS` inside of the toString method this created a closure and because we were not lazily initializing digits this was adding quite a few bytes to the program, with a few simple changes this cuts program size and I tracked length along with the result buffer when stringifying which saves an iteration over the result buffer, and the corresponding helper.
Copy link
Copy Markdown
Member

@ospencer ospencer left a comment

Choose a reason for hiding this comment

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

It seems like we should have a new test for that small bug fix in the bigint printing.

@spotandjake
Copy link
Copy Markdown
Member Author

It seems like we should have a new test for that small bug fix in the bigint printing.

There wasn't really a bug just closures causing the code to get included.

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.

2 participants