Skip to content

fix: cache esbuild transform results per VM to avoid repeated TTY syscalls - #25

Merged
bflad merged 1 commit into
mainfrom
bflad/gen-2690-esbuild-getterminalinfo-syscalls-waste-4s-on-repeated-tty
Mar 9, 2026
Merged

fix: cache esbuild transform results per VM to avoid repeated TTY syscalls#25
bflad merged 1 commit into
mainfrom
bflad/gen-2690-esbuild-getterminalinfo-syscalls-waste-4s-on-repeated-tty

Conversation

@bflad

@bflad bflad commented Mar 6, 2026

Copy link
Copy Markdown
Member

Summary

  • Cache esbuild.TransformResult per VM instance to avoid redundant esbuild.Transform() calls in vm.compile()
  • Each esbuild.Transform() internally calls GetTerminalInfo/IoctlGetTermios to check if stderr is a TTY, which accumulates significant CPU overhead when called hundreds of times during generation
  • The cache is keyed by (name, src) using a struct key and requires no eviction or synchronization since VMs are single-goroutine

@linear

linear Bot commented Mar 6, 2026

Copy link
Copy Markdown

…calls

Each call to esbuild.Transform() internally creates a new stderr logger
that unconditionally calls GetTerminalInfo/IoctlGetTermios to check if
stderr is a TTY. Since vm.compile() is called hundreds of times during
generation (once per template rendered plus setup calls), and many calls
receive the same source string, this accumulates significant CPU overhead.

Cache esbuild.TransformResult per VM instance keyed by (name, src) to
avoid redundant transform calls. The cache is bounded by the number of
unique template sources and requires no eviction or synchronization
since VMs are single-goroutine, where the number of template sources is
not likely to be a concern in practice.
@bflad
bflad force-pushed the bflad/gen-2690-esbuild-getterminalinfo-syscalls-waste-4s-on-repeated-tty branch from 0ff78a4 to b121a5d Compare March 9, 2026 13:00
@bflad

bflad commented Mar 9, 2026

Copy link
Copy Markdown
Member Author

Added RWMutex and rebased with main. 👍

@bflad
bflad merged commit e44fc06 into main Mar 9, 2026
2 checks passed
@bflad
bflad deleted the bflad/gen-2690-esbuild-getterminalinfo-syscalls-waste-4s-on-repeated-tty branch March 9, 2026 13:02
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

Successfully merging this pull request may close these issues.

2 participants