Add interrupt checks to fast array search loops - #1791
Open
josefguenther wants to merge 1 commit into
Open
josefguenther wants to merge 1 commit into
josefguenther wants to merge 1 commit into
Conversation
Contributor
|
Probably that should happen every X elements or we'd make things too slow I think. How much X is, I don't know. |
Contributor
|
@saghul @josefguenther maybe every 2048 elements. that should be fast enough for both cases |
richarddd
suggested changes
Oct 5, 2026
| } | ||
| if (js_get_fast_array(ctx, obj, &arrp, &count)) { | ||
| for (; n < count; n++) { | ||
| if (js_poll_interrupts(ctx)) |
Contributor
There was a problem hiding this comment.
Suggested change
| if (js_poll_interrupts(ctx)) | |
| if (n % 2048 == 0 && js_poll_interrupts(ctx)) |
| } | ||
| if (js_get_fast_array(ctx, obj, &arrp, &count)) { | ||
| for (; n < count; n++) { | ||
| if (js_poll_interrupts(ctx)) |
Contributor
There was a problem hiding this comment.
Suggested change
| if (js_poll_interrupts(ctx)) | |
| if (n % 2048 == 0 && js_poll_interrupts(ctx)) |
| } | ||
| if (js_get_fast_array(ctx, obj, &arrp, &count) && count == len) { | ||
| for (; n >= 0; n--) { | ||
| if (js_poll_interrupts(ctx)) |
Contributor
There was a problem hiding this comment.
Suggested change
| if (js_poll_interrupts(ctx)) | |
| if (n % 2048 == 0 && js_poll_interrupts(ctx)) |
Contributor
|
Whatever number we land on (say it's 2048) we should likely define a constant and use it consistently across the code. |
This branch has not been deployed
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.
#1674 polls in the generic loops of
indexOf,lastIndexOfandincludes, but not in their fast-array loops. So a call on a dense array counts as one tick however long it is, and a loop over such calls reaches the handler every few thousand calls:Seconds between interrupt handler calls, with a loop like the one above (
6a9b531, Release, arm64 macOS):a.indexOf(-1), 1M elementsa.includes(-1), 1M elementsa.lastIndexOf(-1), 1M elementsindexOfon{length: 1e6}This adds the same per-element poll to the three fast loops, plus a test for each in
tests/bug1672/(each hangs on master). The per-call cost on a 1M-element array is unchanged within noise.make test,api-testandtest262show no new failures.Written with AI assistance (Claude Code); I have reviewed the change.