perf: remove redundant work during database initialization#24
Open
lukemcguire wants to merge 1 commit into
Open
perf: remove redundant work during database initialization#24lukemcguire wants to merge 1 commit into
lukemcguire wants to merge 1 commit into
Conversation
- Remove no-op _prepareHashFunctions() call (managers don't exist yet) - Remove unconditional localDatabase.info() network round-trip (unused debug log) - Remove redundant refreshSettings() after init (re-loads WASM a 2nd time)
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.
Eliminate redundant work during database initialization
Three lines that add unnecessary latency to every
initializeDatabase()call:1. Remove no-op
_prepareHashFunctions()callAt the top of
initializeDatabase(),_managersis alwaysundefined— theLiveSyncManagersinstance is created ~20 lines later. So_prepareHashFunctions()(which optional-chains onthis._managers) is a guaranteed no-op that just wastes an async tick. The real hash initialization happens later inmanagers.initialise().2. Remove unconditional
localDatabase.info()callThis makes a network round-trip to CouchDB (
GET /db) on every database initialization purely to log the result atVERBOSElevel. The return value is never used for anything. For remote databases this adds ~500ms+ of latency for a debug log.3. Remove redundant
refreshSettings()after initDirectFileManipulator.init()callsrefreshSettings()immediately afterinitializeDatabase()completes. This re-creates theHashManagerfrom scratch and loads the xxhash WASM module a second time — the first load already happened insideinitializeDatabase()→managers.initialise()→hashManager.initialise(). The only other thingrefreshSettings()does is populatethis.settings, which is already set during construction and the managers' init.Impact
Measured on a headless CLI tool using
DirectFileManipulatoragainst a remote CouchDB:The effect on the Obsidian plugin should be similar proportionally during database open.