Skip to content

perf(utils): add retry limit to autocomplete setup polling#6635

Merged
walterbender merged 2 commits into
sugarlabs:masterfrom
sapnilbiswas:fix-jquery-autocomplete-polling
Apr 15, 2026
Merged

perf(utils): add retry limit to autocomplete setup polling#6635
walterbender merged 2 commits into
sugarlabs:masterfrom
sapnilbiswas:fix-jquery-autocomplete-polling

Conversation

@sapnilbiswas

Copy link
Copy Markdown
Contributor

Description

This pull request fixes a performance bug where jquery-setup.js would keep polling the DOM forever if the #search UI autocomplete didn't start up or if the element wasn't on the current page layout.

The script safely backs off after 10 seconds of polling by adding a retry upper bound (MAX_RETRIES = 20). This stops the background from looping forever and saves the user's CPU and memory cycles.

Related Issues

Fixes #6634

Changes

  • js/utils/jquery-setup.js: Introduced a retries tracking variable and a MAX_RETRIES constant.
  • Modified the recursive else block to only execute setTimeout if retries < MAX_RETRIES.

How Has This Been Tested?

  • Verified that when the element initializes locally, the DOM rendering intercepts perfectly.
  • Simulated an autocomplete failure and verified via the javascript profiler that the function safely terminates and ceases execution after the maximum number of retries is hit, instead of endlessly looping.

Checklist

  • I have read and followed the project's code of conduct.
  • My branch is up-to-date with the upstream master branch.
  • My code follows the project's code style and passes npm run lint.
  • I have tested my changes locally.

PR Category

  • Performance

@github-actions github-actions Bot added performance Improves performance (load time, memory, rendering) size/XS Extra small: < 10 lines changed area/javascript Changes to JS source files labels Apr 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@sapnilbiswas sapnilbiswas marked this pull request as ready for review April 15, 2026 08:52
@Sidharthwin

Sidharthwin commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

@walterbender LGTM

@sapnilbiswas

Copy link
Copy Markdown
Contributor Author

@walterbender Can you please have a look at this when you have time

@walterbender

Copy link
Copy Markdown
Member

Might make sense to add a console error message if the max retries is reached and it fails?

@github-actions github-actions Bot added size/S Small: 10-49 lines changed and removed size/XS Extra small: < 10 lines changed labels Apr 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@sapnilbiswas

Copy link
Copy Markdown
Contributor Author

@walterbender have pushed a new commit that logs a console.error if the initialization fails after hitting MAX_RETRIES
please let me know if there is anything i am missing out on

@walterbender walterbender merged commit e49e8d4 into sugarlabs:master Apr 15, 2026
10 checks passed
e-esakman pushed a commit to e-esakman/musicblocks that referenced this pull request Apr 16, 2026
…#6635)

* perf(utils): add retry limit to autocomplete setup polling

* perf(utils): add console error message on retry failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/javascript Changes to JS source files performance Improves performance (load time, memory, rendering) size/S Small: 10-49 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Performance] Infinite polling loop in jquery-setup.js if #search autocomplete fails

3 participants