Skip to content
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

Tree shake functions using ets counters #28

Open
RoyalIcing opened this issue Apr 19, 2024 · 0 comments
Open

Tree shake functions using ets counters #28

RoyalIcing opened this issue Apr 19, 2024 · 0 comments

Comments

@RoyalIcing
Copy link
Owner

Calls are two steps: there's an Elixir wrapper for the natural experience and autocomplete, and there's the call instruction.

Tree shaking aka dead code elimination is ideal for keeping the resulting modules down. If we use a number formatter but only format unsigned 32-bit ints we should not include the code for formatting floats.

Initially I thought this would require walking through the AST and detecting every call and then removing the functions we noticed were never called.

But there's an even easier way with our two layers. The Elixir call is a real call. We can have an ets table at compile time and increment a counter whenever a function is called, passing the function name as a key. So there's no need to do another pass: we have the Elixir runtime pass already.

We then loop through every function at assembly time and omit the ones that aren't in the ets table. Possibly the counters could be used for some debug output or optimisation (e.g. inlining?)

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