Skip to content

Improve batch update performance and refactor patch logic#40

Closed
zknpr wants to merge 1 commit intomainfrom
update-batch-performance-7821265999889062770
Closed

Improve batch update performance and refactor patch logic#40
zknpr wants to merge 1 commit intomainfrom
update-batch-performance-7821265999889062770

Conversation

@zknpr
Copy link
Copy Markdown
Owner

@zknpr zknpr commented Feb 7, 2026

Improved the performance of batch updates in HostBridge.ts by replacing the sequential fallback loop with Promise.all for parallel execution. This ensures that updates are processed concurrently when the underlying database operation does not support native batching.

Also refactored the JSON patch generation logic into a reusable tryGeneratePatch helper method, improving code maintainability.

Corrected the event firing behavior in the fallback path to emit a single batch event instead of multiple individual events.


PR created automatically by Jules for task 7821265999889062770 started by @zknpr

Refactored `updateCellBatch` in `src/hostBridge.ts` to implement parallel execution for updates when the backend does not support native batching. This replaces the previous sequential fallback loop.

Additionally, extracted JSON patch generation logic into a private helper method `tryGeneratePatch` to reduce code duplication between `updateCell` and `updateCellBatch`.

The fallback implementation now correctly fires a single batch modification event instead of individual events per cell.

Co-authored-by: zknpr <96851588+zknpr@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Feb 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sq-lite-explorer Ready Ready Preview, Comment Feb 7, 2026 1:37pm

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @zknpr, 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 focuses on optimizing the HostBridge's handling of batch updates and improving the maintainability of its JSON patching logic. By parallelizing fallback updates and centralizing patch generation, the changes aim to enhance performance and code quality, while also ensuring correct event emission for batch operations.

Highlights

  • Improved Batch Update Performance: The fallback mechanism for batch updates in HostBridge.ts now processes individual updates in parallel using Promise.all, significantly improving performance when native batching is not supported.
  • JSON Patch Logic Refactoring: The complex logic for generating JSON merge patches has been extracted into a new, reusable private method tryGeneratePatch, enhancing code modularity and maintainability.
  • Corrected Event Emission for Batch Updates: The fallback path for batch updates now ensures that only a single batch edit event is emitted after all updates are processed, preventing redundant event firing.

🧠 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/hostBridge.ts
    • Extracted the JSON merge patch generation logic into a new private helper method, tryGeneratePatch, to promote reusability and cleaner code.
    • Refactored the updateCell method to utilize the new tryGeneratePatch helper for determining JSON patches.
    • Modified the fallback path within updateCellBatch to execute individual cell updates concurrently using Promise.all instead of sequentially.
    • Updated the parallel fallback logic to correctly handle json_patch operations and apply generated patches via document.databaseOperations.updateCell.
    • Ensured that the updateCellBatch method, including its fallback, now consistently results in a single batch edit event being fired.
Activity
  • The pull request was automatically created by Jules for task 7821265999889062770, initiated by user @zknpr.
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.

Copy link
Copy Markdown

@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

This pull request introduces several valuable improvements. The refactoring of the JSON patch generation logic into the tryGeneratePatch method enhances code clarity and maintainability. The performance of batch updates is significantly improved by switching to parallel execution with Promise.all in the fallback path. This change also corrects a bug where individual update events were fired instead of a single batch event, and another where JSON patching was not being applied correctly in the fallback scenario. Overall, these are excellent changes that improve both performance and correctness.

Comment thread src/hostBridge.ts
Comment on lines +900 to +901
(value.startsWith('{') || value.startsWith('[')) &&
(originalValue.startsWith('{') || originalValue.startsWith('['))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The startsWith check is a good performance optimization to avoid unnecessary JSON.parse calls. However, it doesn't account for JSON strings that may have leading whitespace. A valid JSON string like " {...}" would fail this check, preventing a patch from being generated and causing a less efficient full update. Using trim() would make this check more robust.

Suggested change
(value.startsWith('{') || value.startsWith('[')) &&
(originalValue.startsWith('{') || originalValue.startsWith('['))
(value.trim().startsWith('{') || value.trim().startsWith('[')) &&
(originalValue.trim().startsWith('{') || originalValue.trim().startsWith('['))

@zknpr
Copy link
Copy Markdown
Owner Author

zknpr commented Feb 7, 2026

Merged as part of v1.3.0 release in PR #65

@zknpr zknpr closed this Feb 7, 2026
@google-labs-jules
Copy link
Copy Markdown
Contributor

Merged as part of v1.3.0 release in PR #65

Acknowledged. Glad to hear the changes are merged.

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.

1 participant