Repository navigation
Route outbound messages to their compilation by ID - #460
Open
mattlewis92 wants to merge 1 commit into
Open
mattlewis92 wants to merge 1 commit into
mattlewis92 wants to merge 1 commit into
Conversation
Each Dispatcher filtered the shared outbound message stream for its own compilation ID, so every message cost O(in-flight compilations) and a batch of N concurrent compilations cost O(N^2). MessageTransformer now routes each message to its compilation's subscriber with a Map lookup.
Contributor
|
The principle seems sound. Just to confirm per our contribution guidelines, this PR was made without the use of LLMs? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every
Dispatchersubscribes to the compiler's shared outbound message stream and filters it for its own compilation ID. Each message therefore runs once per in-flight compilation, so N concurrentcompileStringAsync()calls cost O(N²) on the main thread. Bundlers start one compilation per stylesheet, often thousands at once.MessageTransformernow routes each message to its compilation's subscriber with aMaplookup, andDispatcherreceives only its own compilation's messages. When the stream errors or completes, every compilation's subscription errors or completes, and so does any subscription made after that, as with the shared stream before.Benchmark
N concurrent
compileStringAsync()calls, each@use-ing 6 partials through an async custom importer. Both builds use the same 1.108.0 compiler, and the output is identical.mainWith at most 16 compilations in flight, both take about 2.1 s for 7,300 files.
Benchmark script
Testing
npm test: new tests inmessage-transformer.test.tsfor routing, reused compilation IDs, and errors and completion reaching every compilation.npm run checkandnode test/after-compile-test.mjspass.js-api-speclocally.