perf(@angular/build): batch last_accessed updates in sqlite cache store - #33801
Merged
Merged
Conversation
alan-agius4
force-pushed
the
perf-sqlite-cache-batch
branch
from
August 7, 2026 14:27
4733e81 to
e2805e9
Compare
alan-agius4
marked this pull request as ready for review
August 7, 2026 14:28
alan-agius4
force-pushed
the
perf-sqlite-cache-batch
branch
from
August 7, 2026 14:28
e2805e9 to
97b7ff9
Compare
There was a problem hiding this comment.
Code Review
This pull request optimizes the SqliteCacheStore by batching SQLite access updates in a transaction instead of executing them individually on every cache hit. It also configures performance-related SQLite PRAGMAs and ensures pending updates are flushed upon closing. The review feedback suggests using BEGIN IMMEDIATE TRANSACTION; instead of BEGIN TRANSACTION; to prevent potential SQLITE_BUSY errors or deadlocks in concurrent environments.
Previously, every `get()` call on `SqliteCacheStore` immediately executed an `UPDATE` statement to refresh the `last_accessed` timestamp for the requested cache key. In SQLite WAL mode, each unbatched `UPDATE` starts an implicit write transaction, acquiring exclusive write locks on the WAL and causing repeated disk I/O and fsync operations during cache reads. During parallel builds, this serialized concurrent read operations and introduced unnecessary overhead on hot read paths. To resolve this: - `last_accessed` updates are buffered in an in-memory `Set` and flushed inside a single explicit transaction (`BEGIN TRANSACTION; ... COMMIT;`), periodically debounced (every 500ms or when batch reaches 100 entries) and before pruning on `close()`. - Flushes on `close()` ensure that recently accessed items have their timestamps persisted prior to TTL and LRU size pruning. - SQLite PRAGMAs (`busy_timeout = 5000`, `temp_store = MEMORY`, `mmap_size = 268435456`) are tuned to reduce lock contention and leverage memory-mapped I/O. - The debounced timer uses `unref()` to ensure it does not hold the Node.js process event loop open.
alan-agius4
force-pushed
the
perf-sqlite-cache-batch
branch
from
August 7, 2026 14:32
97b7ff9 to
b370ccf
Compare
clydin
approved these changes
Aug 7, 2026
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, every
get()call onSqliteCacheStoreimmediately executed anUPDATEstatement to refresh thelast_accessedtimestamp for the requested cache key. In SQLite WAL mode, each unbatchedUPDATEstarts an implicit write transaction, acquiring exclusive write locks on the WAL and causing repeated disk I/O and fsync operations during cache reads.During parallel builds, this serialized concurrent read operations and introduced unnecessary overhead on hot read paths.
To resolve this:
last_accessedupdates are buffered in an in-memorySetand flushed inside a single explicit transaction (BEGIN TRANSACTION; ... COMMIT;), periodically debounced (every 500ms or when batch reaches 100 entries) and before pruning onclose().close()ensure that recently accessed items have their timestamps persisted prior to TTL and LRU size pruning.busy_timeout = 5000,temp_store = MEMORY,mmap_size = 268435456) are tuned to reduce lock contention and leverage memory-mapped I/O.unref()to ensure it does not hold the Node.js process event loop open.