Skip to content

perf: format small embedded text on the thread of the plugin - #1485

Merged
dsherret merged 2 commits into
mainfrom
perf/thread-host-format
Nov 30, 2026
Merged

dsherret merged 2 commits into
mainfrom
perf/thread-host-format

Conversation

@dsherret

Copy link
Copy Markdown
Member

When a Wasm plugin formatted embedded text with another plugin, the request went to the runtime's thread and then to another plugin's thread and back. The thread formatting a batch of files now keeps its own instance of the embedded text's plugin and calls it directly.

This is only done for text up to 64KB (handing over larger text costs little compared to formatting it) and one level deep. Everything else goes through the runtime as before: process plugins, plugins whose configuration was not checked yet, when the embedded text needs to be made stable, and when the plugin panics or runs out of stack.

Both instances run on the same native stack, and each may use up to 8MB of it. The thread's stack stays at 11MB, and it goes through the runtime when not enough is left. Plugins had used at most 118KB out of the 2MB they may use when measuring real ones with deeply nested documents (ex. 200 nested <div>s).

Things to know:

  • There may be an additional instance of an embedded plugin for each thread that formats. I have not measured the memory usage.
  • An embedded plugin that panics is run one more time than before, because the runtime then tries again.

Synthetic benchmarks with plugins that do little work on Linux:

Before After
2,000 files with an embed 13.3ms 9.2ms
100 files with 100 embeds 36.3ms 13.1ms
100 files with 50 embeds and override config 23.0ms 10.9ms
100 files with 100 embeds no plugin formats 18.5ms 4.6ms

@dsherret
dsherret merged commit fb6a3a3 into main Nov 30, 2026
6 checks passed
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.

1 participant