Repository navigation
feat(cdp): let a caller bound hog and liquid rendering with a deadline #133495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
trunk-io
merged 13 commits into
feat/node-store-upload-route
from
feat/node-store-render-deadline
Nov 11, 2026
+702
−31
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
288cf61
feat(cdp): let a caller bound hog and liquid rendering with a deadline
Silthus 781911a
fix(cdp): stop rendering once the deadline passes between liquid leav…
Silthus 5e7d68d
chore(cdp): assert the time a liquid input spends past its deadline
Silthus a1a6e32
fix(cdp): stop a hog input that waits for the render semaphore once i…
Silthus 32d13cc
fix(cdp): drop a cancelled semaphore waiter in constant time
Silthus 527fb8a
chore(cdp): bench the semaphore abort in the serial suite
Silthus daeea5e
chore(cdp): move the semaphore abort bench under dev/
Silthus e9a810a
fix(cdp): register one abort listener per deadline for queued hog ren…
Silthus cd5bb1a
chore(cdp): cover a deadline that passes after one leaf of an input t…
Silthus 024fd7b
chore(cdp): let the queued leaf finish before the test restores real …
Silthus 9d0d9e3
fix(cdp): keep the deadline error unstamped when builds share a deadline
Silthus 9702e97
Merge remote-tracking branch 'origin/master' into feat/node-store-ren…
Silthus 105fed9
Merge branch 'feat/node-store-upload-route' into feat/node-store-rend…
Silthus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| import { configureEventLoopYield, getEventLoopYieldThresholdMs } from '~/common/utils/event-loop-yield' | ||
|
|
||
| import { execHog } from '../utils/hog-exec' | ||
|
|
||
| describe('hog render queue benchmark', () => { | ||
| const CEILING_MS = 1000 | ||
| const leaf = ['_H', 1, 32, 'x'] | ||
|
|
||
| it('queues and drops 50,000 renders that share a deadline under the ceiling', async () => { | ||
| const threshold = getEventLoopYieldThresholdMs() | ||
| configureEventLoopYield(0) | ||
| jest.useFakeTimers({ | ||
| doNotFake: [ | ||
| 'hrtime', | ||
| 'nextTick', | ||
| 'queueMicrotask', | ||
| 'setImmediate', | ||
| 'clearImmediate', | ||
| 'setInterval', | ||
| 'clearInterval', | ||
| 'Date', | ||
| ], | ||
| }) | ||
| const nextTurn = (): Promise<void> => new Promise((resolve) => setImmediate(resolve)) | ||
| try { | ||
| let first: Awaited<ReturnType<typeof execHog>> | undefined | ||
| void execHog(leaf).then((outcome) => (first = outcome)) | ||
| for (let turn = 0; jest.getTimerCount() === 0 && turn < 1000; turn++) { | ||
| await nextTurn() | ||
| } | ||
| const deadline = new AbortController() | ||
| const queuedAt = process.hrtime.bigint() | ||
| const queued = Array.from({ length: 50_000 }, () => execHog(leaf, undefined, deadline.signal)) | ||
| const queueMs = Number(process.hrtime.bigint() - queuedAt) / 1_000_000 | ||
| await nextTurn() | ||
|
|
||
| const abortedAt = process.hrtime.bigint() | ||
| deadline.abort(new DOMException('The deadline passed', 'TimeoutError')) | ||
| const abortMs = Number(process.hrtime.bigint() - abortedAt) / 1_000_000 | ||
| const outcomes = await Promise.all(queued) | ||
|
|
||
| expect(outcomes.every((outcome) => outcome.error?.name === 'TimeoutError')).toBe(true) | ||
| expect(queueMs).toBeLessThan(CEILING_MS) | ||
| expect(abortMs).toBeLessThan(CEILING_MS) | ||
| for (let turn = 0; first === undefined && turn < 1000; turn++) { | ||
| jest.runOnlyPendingTimers() | ||
| await nextTurn() | ||
| } | ||
| expect(first?.execResult?.result).toBe('x') | ||
| } finally { | ||
| jest.useRealTimers() | ||
| configureEventLoopYield(threshold) | ||
| } | ||
| }) | ||
| }) |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| const expiresAt = new WeakMap<AbortSignal, number>() | ||
|
|
||
| export function deadlineAfter(ms: number): AbortSignal { | ||
| const signal = AbortSignal.timeout(ms) | ||
| expiresAt.set(signal, performance.now() + ms) | ||
| return signal | ||
| } | ||
|
|
||
| export function deadlineError(signal: AbortSignal | undefined): unknown { | ||
| if (!signal) { | ||
| return undefined | ||
| } | ||
| if (signal.aborted) { | ||
| return signal.reason | ||
| } | ||
| const at = expiresAt.get(signal) | ||
| return at !== undefined && performance.now() >= at | ||
| ? new DOMException('The operation was aborted due to timeout', 'TimeoutError') | ||
| : undefined | ||
| } | ||
|
|
||
| export function deadlineRemainingMs(signal: AbortSignal | undefined): number | undefined { | ||
| const at = signal && expiresAt.get(signal) | ||
| return at === undefined ? undefined : Math.max(0, at - performance.now()) | ||
| } | ||
|
|
||
| export function throwIfDeadlinePassed(signal: AbortSignal | undefined): void { | ||
| const error = deadlineError(signal) | ||
| if (error !== undefined) { | ||
| throw error | ||
| } | ||
| } |
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
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
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
1 change: 1 addition & 0 deletions
1
...xtures/hog-bytecode/0a7c9f2282f0c526ba09f04bf535ef197338f8ac69ac218fbbc3c489fc7872f7.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ["_H",1,32,"busy_until",32,"properties",32,"event",1,3,2,"now",0,2,"toUnixTimestampMilli",1,15,40,2,39,-19,32,"done",38] |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.