Skip to content

fix(sql_connect): Refactor to improve caching performance for large result sets#18430

Open
aashishpatil-g wants to merge 4 commits into
mainfrom
ap/cacheIsolate
Open

fix(sql_connect): Refactor to improve caching performance for large result sets#18430
aashishpatil-g wants to merge 4 commits into
mainfrom
ap/cacheIsolate

Conversation

@aashishpatil-g

@aashishpatil-g aashishpatil-g commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Description

Large query caching can block main thread as it tries to normalize the data and write to sqlite. Moving this logic off the main thread to a separate isolate will prevent locking the main thread. Other optimizations

  • Use prepared sql statements
  • Use of a transaction to wrap the full normalization process to consolidate multiple writes.

These changes only impact native platforms. Web caching is still done on main isolate as isolates aren't supported on web. Web performance will be a future topic.

Also, added tests for

  • Unit test for Parsing and storing large query result set
  • Unit test to ensure main thread isn't blocked during caching
  • Added integration test for caching.

Related Issues

Fixes - firebase/firebase-tools#10776

Breaking Change

This is NOT a breaking change.

Large query caching can block main thread as it tries to normalize the data and write to sqlite. Moving this logic off the main thread to a separate isolate will prevent locking the main thread. Other optimizations also include prepared sql statements and use of a transaction to wrap the full normalization process to consolidate multiple writes.
@gemini-code-assist

Copy link
Copy Markdown
Contributor
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 the 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 counterproductive. 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.

@aashishpatil-g

Copy link
Copy Markdown
Contributor Author

/gemini review

@aashishpatil-g aashishpatil-g changed the title fix: Refactor to improve caching performance for large result sets fix(sql_connect): Refactor to improve caching performance for large result sets Jul 10, 2026

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

Copy link
Copy Markdown
Contributor

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 background isolate processing for the Firebase Data Connect cache on non-web platforms to prevent blocking the main thread during large result tree normalization, alongside adding transaction support and resource disposal to cache providers. The review feedback highlights critical issues in the isolate implementation, including potential database locks and corruption due to concurrent message processing, a race condition and resource leak in ReceivePort handling, and unhandled asynchronous exceptions from unreturned completers. Additionally, robust error handling is recommended for SQLite3CacheProvider to prevent LateInitializationError and connection leaks if initialization fails.

Comment thread packages/firebase_data_connect/firebase_data_connect/lib/src/cache/cache.dart Outdated
Comment thread packages/firebase_data_connect/firebase_data_connect/lib/src/cache/cache.dart Outdated
Comment thread packages/firebase_data_connect/firebase_data_connect/lib/src/cache/cache.dart Outdated
Comment on lines +23 to +25
final int directedBy_deleteMany;
final int movie_deleteMany;
final int person_deleteMany;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

what change results in the renaming of the generated file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There were some changes done recently to support batch mutations. I suspect this might have caused the code generator to change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Took a look at the gql operation definitions.

The example project got regenerated and this correctly matches the gql definitions. Its possible the original names had been manually tweaked in the generated code.

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.

2 participants