Comment

Comment by paulddraper

This is just tracing GC. Nothing more or less than that.

The only difference is how you construct the closure record for your GC.

Using the example:

  function f() {
    const a = {};
    const b = {};
    return [
      () => a,
      () => b,
    ];
  }
You can choose to have one scope record shared by both functions, or individual record.

  function1 ----|   ----> a
                v   |
                scope
                ^   |
  function2 ----|   ----> b
Or

  function1 --> scope1 --> a

  function2 --> scope2 --> b
JS engines choose to do the former, not out of simplicity (arguably it's more complicated), but due to performance.
parent paulddraper 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton