Skip to content

Super compact variables #1343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gfwilliams opened this issue Feb 16, 2018 · 2 comments
Closed

Super compact variables #1343

gfwilliams opened this issue Feb 16, 2018 · 2 comments

Comments

@gfwilliams
Copy link
Member

gfwilliams commented Feb 16, 2018

It occurred to me that in a lot of targets we now have around 5000 variables, but we're using 16 bit references - so a few bits are being lost.

Not only that but on the <1024 byte targets we're using up some JsFlags bits to store reference info, and those would be amazingly useful for some more global flags like visible/const/etc.

So I just had a quick go at throwing GCC's packed bits at it, and... it works!

https://github.com/espruino/Espruino/tree/experimental_compact_vars

This only works in GCC 4.4 and later it seems because they improved the bit packing behaviour, but for something like Puck.js (2250 vars) it drops the var size from 16 to 13 bytes, allowing you to bump the available vars to 2769.

Obviously this destroys alignment, so I'm unsure of how well (or quickly) this'll work, but it's an interesting start.

Just to add: strangely this is actually less efficient for normal Strings, which now only store 9 bytes of characters for a 13 byte variable, where before they managed 12 bytes out of 16. However Espruino tries to allocate flat strings where it seems sensible, so it's less of a big deal.

@gfwilliams
Copy link
Member Author

Some notes on this here: #1631

Looks promising.

@gfwilliams
Copy link
Member Author

This is now merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant