Skip to content

Optimized file checks via concurrent Promise.all and cleaned code.#1494

Open
tushar743-ui wants to merge 1 commit into
processing:mainfrom
tushar743-ui:fix/improve_openprocessing.ts_in_api
Open

Optimized file checks via concurrent Promise.all and cleaned code.#1494
tushar743-ui wants to merge 1 commit into
processing:mainfrom
tushar743-ui:fix/improve_openprocessing.ts_in_api

Conversation

@tushar743-ui

Copy link
Copy Markdown

Formatting: Normalized inconsistent spacing .

Parallelized existence checks: Replaced the sequential for...of loop awaiting exists() one sketch at a time with Promise.all(allSketches.map(...)), so all file-existence checks run concurrently instead of blocking one-by-one.

Simplified return: Filtered allSketches directly against the resolved existence results instead of building availableSketches via push-in-a-loop, then dropped the pointless return [...availableSketches] spread in favor of returning the array directly.

Why: the original loop serialized an I/O-bound check (exists) per sketch, which is unnecessarily slow when the list grows; batching with Promise.all cuts wall-clock time while keeping identical output.

Signed-off-by: tushar743-ui <tusharpatle743@gmail.com>
Copilot AI review requested due to automatic review settings July 2, 2026 11:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the performance and clarity of getCurationSketches() by parallelizing cached sketch-file existence checks and simplifying the resulting filtering/return flow.

Changes:

  • Normalized formatting for the priorityIds list.
  • Replaced sequential await exists(...) checks with concurrent Promise.all(...) checks.
  • Simplified sketch availability filtering and returned the filtered array directly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Nwakaego-Ego

Copy link
Copy Markdown
Collaborator

Hi @tushar743-ui, thank you for this PR. I looked into it and wanted to share some thoughts.

Looking at the live site at p5js.org/community/, the sketches load without any noticeable delay for users. The exists() function imports from node:fs/promises, which confirms it runs at build time, not when a user visits the page.

Since no issue was opened for this, it is hard to know what specific problem is being solved. The p5.js website has a contributing process where changes like this should start with an issue. I may be missing context, so opening an issue would help the community weigh in on whether this optimisation is needed and the best approach to take.

Please check the README for more on the contributing process.

cc @doradocodes @ksen0

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.

3 participants