fix(ext/node): run node:sqlite backup off the main thread - #36581
Open
Tango992 wants to merge 3 commits into
Open
fix(ext/node): run node:sqlite backup off the main thread#36581Tango992 wants to merge 3 commits into
node:sqlite backup off the main thread#36581Tango992 wants to merge 3 commits into
Conversation
`backup()` from `node:sqlite` returned a promise, but the copy was done entirely inside a synchronous op: the whole `sqlite3_backup_step` loop ran on the main thread before the promise settled, so the event loop was blocked for the duration of the backup and the `rate`/`progress` options had no practical effect on responsiveness. Split the single `op_node_database_backup` op into an init/step/finish sequence backed by a `BackupJob` resource that owns the raw `sqlite3_backup` handle. Each `sqlite3_backup_step` now runs on the blocking threadpool via `spawn_blocking` and yields at the await point, mirroring Node's `BackupJob`/`ThreadPoolWork`. When no `progress` callback is given, `op_node_database_backup_run` drives the loop in Rust to avoid a JS round-trip per step, while still awaiting each step.
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.
backup()fromnode:sqlitereturned a promise, but the copy was done entirely inside a synchronous op: the wholesqlite3_backup_steploop ran on the main thread before the promise settled, so the event loop was blocked for the duration of the backup and therate/progressoptions had no practical effect on responsiveness.Split the single
op_node_database_backupop into an init/step/finish sequence backed by aBackupJobresource that owns the rawsqlite3_backuphandle. Eachsqlite3_backup_stepnow runs on the blocking threadpool viaspawn_blockingand yields at the await point, mirroring Node'sBackupJob/ThreadPoolWork. When noprogresscallback is given,op_node_database_backup_rundrives the loop in Rust to avoid a JS round-trip per step, while still awaiting each step.Changes in this PR were assisted using Claude