montylang / monty

Language from a parallel universe where Python is functional
https://montylang.github.io/docs/
BSD 3-Clause "New" or "Revised" License
5 stars 0 forks source link

List of premature optimizations #31

Open elimirks opened 3 years ago

elimirks commented 3 years ago

Pass small ADTs by value

We can probably be clever with allocations for ADTs with few parameters. As in, pass them by value rather than allocate memory for all of them. A Maybe or Either type takes up a trivial amount more memory than whatever it contains, so it's probably worth just copying it instead of returning a reference or passing a reference to a function.

If all elements in an ADT only have 1 data slot, pass them by value instead of reference

If a closure environment doesn't contain non root references, make it a function

In version 1 of the compiler we're just making everything a closure, which is a bit pointless for functions that only have root level references

Try to store lists contiguously

The V1 allocator will be pretty dumb with lists, slotting them wherever possible. To utilize the cache better, we should try to store lists in contiguous memory.

Extending onto this, if you map over a list, it can trivially be given a contiguous memory block

Cache compiled library code

Instead of recompiling the entire stdlib for every program, cache the compiled libraries

Use TrieMap to prune redundant expressions and function definitions