typescript-go icon indicating copy to clipboard operation
typescript-go copied to clipboard

Various node builder related performance optimizations

Open jakebailey opened this issue 6 months ago • 2 comments

Did some profiling of this overnight.

  • Eliminate the closures; this can be done through the same tricks used in the parser to avoid binding. This reduces some 10%+ allocations.
  • Presize nonTypeOnlyNames.
  • Eliminate the closures from the emit context.
  • Reuse emit contexts in type baselines.

jakebailey avatar May 30 '25 21:05 jakebailey

Kinda; in this case I'm changing it because the rebinding was very expensive (the most allocation done by the new code).

For ephemeral stuff like the checker, just using fields is more ergonomic and not much slower. For these kinds of pooled / reused / reset resources, managing the fields is kind of annoying, so passing in a method directly (*Parser).parseSomething to another method on the same type for a simple callback is not too inergonomic.

The core helpers I like the least and arguably could just be removed from this PR as I don't think they actually helped perf in my testing.

jakebailey avatar Jun 02 '25 19:06 jakebailey

I checked, and the captures I "avoided" with the core package changes don't matter. The functions are so small that I believe the compiler is figuring it out (either by inlining, but most likely by realizing that the closure is not leaked to the heap).

image

jakebailey avatar Jun 02 '25 20:06 jakebailey