Add per-context interrupt budget#1526
Conversation
|
Can you check in before/after style if this change impacts tests/microbench.js? |
|
I ran a before/after Setup:
Results: Summary: The run-to-run noise on this machine is fairly high (about 4-5% RSD on total score), so I would not read this as a strong regression signal. The observed total-score delta is small relative to noise. The change only adds work in |
|
Can you try to run the v8 benchmark? See: https://github.com/quickjs-ng/benchmarks |
|
@saghul Sure — I ran the V8 benchmark from Setup:
Median results:
Raw total scores: Summary: the V8 benchmark looks neutral on my machine. Median score is essentially unchanged ( |
| JSRuntime *rt = ctx->rt; | ||
| ctx->interrupt_counter = JS_INTERRUPT_COUNTER_INIT; | ||
| ctx->interrupt_count++; | ||
| if (ctx->interrupt_limit > 0 && ctx->interrupt_count >= ctx->interrupt_limit) { |
There was a problem hiding this comment.
| if (ctx->interrupt_limit > 0 && ctx->interrupt_count >= ctx->interrupt_limit) { | |
| if (unlikely(ctx->interrupt_limit > 0) && ctx->interrupt_count >= ctx->interrupt_limit) { |
Add a context-local interrupt counter and optional limit.
The counter increments when the interpreter reaches the existing interrupt polling path. If a context limit is set and the counter reaches it, that context throws
interruptedbefore consulting the runtime-level interrupt handler. A limit of0keeps the feature disabled.This is useful for embedders that host multiple
JSContextinstances inside oneJSRuntimeand need each context to have an independent execution budget. In QuickBEAM, a pool worker owns oneJSRuntimeand creates many contexts withJS_NewContext(rt). A runtime-level interrupt handler remains useful as a global guard, but it cannot express a per-context budget for that pooled model.Tested: