Skip to content

[diffs] WorkerPool & Element Pool Hardening#737

Merged
amadeus merged 3 commits into
mainfrom
amadeus/worker-pool-hardening
May 24, 2026
Merged

[diffs] WorkerPool & Element Pool Hardening#737
amadeus merged 3 commits into
mainfrom
amadeus/worker-pool-hardening

Conversation

@amadeus
Copy link
Copy Markdown
Member

@amadeus amadeus commented May 23, 2026

Basically the theme switcher branch for diffshub has exposed a ton of flaws in my WorkerPoolManager and element pooling architecture that are essentially fixed here.

The fixes are grouped into 3 commits that address a few important scenarios.

Clean renderCache on worker pool theme change

When the worker pool has a theme change, we need to blow away our existing render cache to ensure we never render from a stale theme. Additionally this helps the theme change feel instant/responsive because we can render plain text right away and not wait for a response from the worker.

WorkPoolManager.setRenderOptions race conditions

The core change here was that given the async nature of loading/setting themes (both to load the theme and update the workers), we needed better validation under rapid theme changes to ensure that tasks are properly dropped and if things come back out of order they can be properly ignored.

Fixing poisoned elements

While we were clearing the element pool correctly on theme changes, there was another bug wherein if we were recycling on that tick we were then pooling invalid elements. So this added a sort of version tracker for the element pool that gets incremented and tied to versioned renders to ensure that pooled element contract is always correct with its children

amadeus added 3 commits May 23, 2026 16:08
This will ensure immediate plaintext updates
When it cames to render options updating, there were a ton of potential
race conditions and extra delays that were incurred, this should fix
most of them.

* Proper invalidate render option updates if they overlap
* Ensure that invalid highlighting jobs are discarded
There were a variety of race conditions where an element could be pooled
and re-claimed when it's shadow dom was actually invalid.  This should
fix all of those cases from before

Also improved the max size for the element tool to dynamically adjust to
possible render windows to reduce general unnecessary pooling thrash.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pierre-docs-diffshub Ready Ready Preview May 23, 2026 11:21pm
pierre-docs-trees Ready Ready Preview May 23, 2026 11:21pm
pierrejs-diff-demo Ready Ready Preview May 23, 2026 11:21pm
pierrejs-docs Ready Ready Preview May 23, 2026 11:21pm

Request Review

@amadeus amadeus changed the title [diffs] WorkerPool Hardening [diffs] WorkerPool & Element Pool Hardening May 23, 2026
@amadeus amadeus requested a review from necolas May 23, 2026 23:48
item.instance.primeHighlightCache();
}

private getElementPoolLimit() {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another smol optimization that went into here -- in fully collapsed diff views, i was noticing that we were blowing our max pool windows constantly, so I reworked the max size to better fit the max collapsed items we might render. Also made it larger for isContainerManaged which actually means elements need an extra tick to be cleaned up before they can be re-cycled.

@amadeus amadeus merged commit a79965b into main May 24, 2026
12 checks passed
@amadeus amadeus deleted the amadeus/worker-pool-hardening branch May 24, 2026 05:17
amadeus added a commit that referenced this pull request May 24, 2026
* Manually clear renderCache on theme change for WorkerPool

This will ensure immediate plaintext updates

* Fix a ton of WorkerPoolManager race conditions

When it cames to render options updating, there were a ton of potential
race conditions and extra delays that were incurred, this should fix
most of them.

* Proper invalidate render option updates if they overlap
* Ensure that invalid highlighting jobs are discarded

* Fix poisoned element pool

There were a variety of race conditions where an element could be pooled
and re-claimed when it's shadow dom was actually invalid.  This should
fix all of those cases from before

Also improved the max size for the element tool to dynamically adjust to
possible render windows to reduce general unnecessary pooling thrash.
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