You are browsing as a guest. Sign up (or log in) to start making projects!

3h 54m 17s logged

Sealed enums and faster GC

  • I added a new type of object, sealed enums:
sealed enum Animal {
     Cat(str name, int age, bool isMeowing),
     Dog(str name, int age),
     Unknown
}

They allow for storing data inside enums, they’re very similar to rust enums:

sealed enum Result<T> {
     Success(T out),
     Failure
}
  • I also refactored lambdas to use a sealed enum instead of a big struct:
//before
struct LambdaCaptures(Lambda0Captures? c0, Lambda1Captures? c1, Lambda2Captures? c2);

//after
sealed enum LambdaCaptures {
    Lambda0Captures(Box$int capture0, ...),
    Lambda1Captures(Box$float capture0, ...)
}

Sealed enums only store a tag and a pointer, so if you use a lot of lambdas, this will save a TON of heap space

  • Faster garbage collector!
    I made the marking phase of the mark and sweep collector faster by using an epoch based cleanup approach
    Now, instead of clearing and re-populating the marked list, we don’t ever clear it and we invalidate it by just increasing the epoch.
    This makes the isMarked check go from O(n) to O(1) while also improving marking speed because scratch doesn’t have to resize our list
0
29

Comments 0

No comments yet. Be the first!