Skip to content

parallelize generation and notification paths with Promise.all#1687

Open
brdandu wants to merge 1 commit intoproject-chip:masterfrom
brdandu:task/improveZapPerformance/ZAP#1659
Open

parallelize generation and notification paths with Promise.all#1687
brdandu wants to merge 1 commit intoproject-chip:masterfrom
brdandu:task/improveZapPerformance/ZAP#1659

Conversation

@brdandu
Copy link
Collaborator

@brdandu brdandu commented Feb 17, 2026

  • Template engine: run iterative iterations (e.g. per-cluster) and deferred blocks in parallel; use per-iteration options to avoid races.
  • Generation engine: load template JSON files and package options in parallel; run generateAndWriteFiles for multiple template packages in parallel per .zap file.
  • ClustersHelper: fetch cluster details per endpoint in parallel in loadEndpoints().
  • helper-endpointconfig: resolve attribute default values in parallel per cluster, then process in order.
  • query-session-notification: run deleteNotification and setWarningIfMessageNotExists in parallel where multiple IDs/messages are handled.
  • Github ZAP#1659

- Template engine: run iterative iterations (e.g. per-cluster) and
  deferred blocks in parallel; use per-iteration options to avoid races.
- Generation engine: load template JSON files and package options in
  parallel; run generateAndWriteFiles for multiple template packages
  in parallel per .zap file.
- ClustersHelper: fetch cluster details per endpoint in parallel in
  loadEndpoints().
- helper-endpointconfig: resolve attribute default values in parallel
  per cluster, then process in order.
- query-session-notification: run deleteNotification and
  setWarningIfMessageNotExists in parallel where multiple IDs/messages
  are handled.
- Github ZAP#1659
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @brdandu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the performance of various operations across the application by introducing parallel execution using 'Promise.all'. The changes target several key areas, including database notification handling, template generation, cluster data loading, and attribute configuration, to reduce overall processing time and enhance responsiveness.

Highlights

  • Database Notification Parallelization: Parallelized database notification operations by replacing sequential loops with 'Promise.all' for deleting notifications and setting warnings, improving responsiveness.
  • Template Engine Performance: Improved template engine performance by running iterative iterations and deferred blocks in parallel using 'Promise.all', reducing generation time.
  • Generation Engine Efficiency: Enhanced generation engine efficiency by loading template JSON files and package options concurrently, and executing 'generateAndWriteFiles' for multiple template packages in parallel.
  • Cluster Data Loading Optimization: Accelerated cluster data loading in 'ClustersHelper' by fetching cluster details for multiple endpoints in parallel, speeding up data retrieval.
  • Attribute Default Value Resolution: Optimized attribute default value resolution in 'helper-endpointconfig' by processing them in parallel per cluster, improving configuration loading.
  • Startup Generation Parallelization: Updated 'startup.js' to parallelize the execution of 'generatorEngine.generateAndWriteFiles' for multiple template packages, leading to faster application startup.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src-electron/db/query-session-notification.js
    • Replaced sequential deletion of notifications with 'Promise.all' for parallel execution.
    • Converted sequential warning message setting to parallel execution using 'Promise.all'.
    • Parallelized deletion of notifications based on patterns using 'Promise.all'.
  • src-electron/generator/generation-engine.js
    • Implemented parallel loading of template JSON files using 'Promise.all'.
    • Parallelized the fetching of output and generator options for multiple packages using 'Promise.all'.
  • src-electron/generator/helper-endpointconfig.js
    • Resolved attribute default values in parallel for all attributes within an endpoint using 'Promise.all'.
  • src-electron/generator/matter/app/zap-templates/common/ClustersHelper.js
    • Fetched cluster details for all endpoints in parallel using 'Promise.all'.
  • src-electron/generator/template-engine.js
    • Parallelized the production of iterative content by mapping and resolving iterations with 'Promise.all'.
    • Rendered deferred blocks in parallel using 'Promise.all' and joined the results.
  • src-electron/main-process/startup.js
    • Executed 'generateAndWriteFiles' for multiple template packages in parallel using 'Promise.all'.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@brdandu brdandu linked an issue Feb 17, 2026 that may be closed by this pull request
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request successfully parallelizes several asynchronous paths in the template and generation engines, which should improve performance during file generation and notification handling. Key improvements include the use of per-iteration options in produceIterativeContent to avoid race conditions and the parallelization of DB queries for cluster details and attribute defaults. However, some parallelized paths introduce race conditions, specifically in notification creation and generation logging, which need to be addressed to ensure data consistency. Additionally, the parallelization of template loading is currently limited by global database transaction locks.

Comment on lines +210 to +214
await Promise.all(
warningMessage.map((message) =>
setWarningIfMessageNotExists(db, sessionId, message)
)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Parallelizing setWarningIfMessageNotExists introduces a race condition. Since this function performs a "check-then-insert" operation without a database lock or transaction, concurrent calls for the same message (or duplicate messages in the array) can result in multiple identical notifications being created. It is safer to process these sequentially to maintain the uniqueness check.

    for (const message of warningMessage) {
      await setWarningIfMessageNotExists(db, sessionId, message)
    }

Comment on lines +602 to +604
const loadResults = await Promise.all(
filesToLoad.map((jsonFile) => loadGenTemplatesJsonFile(db, jsonFile))
)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

While Promise.all is used here to parallelize template loading, the underlying loadGenTemplatesJsonFile function is constrained by a global database transaction lock (dbApi.dbBeginTransaction). This results in serialized execution at the database level, with concurrent calls polling the lock every 100ms, which negates the performance benefits of parallelization for the database-heavy portions of the task.

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.

Code generation slow and seemingly single-threaded

1 participant