Skip to content

perf: remove redundant work during database initialization#24

Open
lukemcguire wants to merge 1 commit into
vrtmrz:mainfrom
lukemcguire:perf/remove-redundant-init-work
Open

perf: remove redundant work during database initialization#24
lukemcguire wants to merge 1 commit into
vrtmrz:mainfrom
lukemcguire:perf/remove-redundant-init-work

Conversation

@lukemcguire

Copy link
Copy Markdown

Eliminate redundant work during database initialization

Three lines that add unnecessary latency to every initializeDatabase() call:

1. Remove no-op _prepareHashFunctions() call

At the top of initializeDatabase(), _managers is always undefined — the LiveSyncManagers instance is created ~20 lines later. So _prepareHashFunctions() (which optional-chains on this._managers) is a guaranteed no-op that just wastes an async tick. The real hash initialization happens later in managers.initialise().

2. Remove unconditional localDatabase.info() call

This makes a network round-trip to CouchDB (GET /db) on every database initialization purely to log the result at VERBOSE level. 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 init

DirectFileManipulator.init() calls refreshSettings() immediately after initializeDatabase() completes. This re-creates the HashManager from scratch and loads the xxhash WASM module a second time — the first load already happened inside initializeDatabase()managers.initialise()hashManager.initialise(). The only other thing refreshSettings() does is populate this.settings, which is already set during construction and the managers' init.

Impact

Measured on a headless CLI tool using DirectFileManipulator against a remote CouchDB:

Operation Before After
Single-file operation (read/meta/delete) ~7s ~1s

The effect on the Obsidian plugin should be similar proportionally during database open.

- 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)
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