Skip to content

perf(startup): load the code editor only when a code block is drawn - #13631

Closed
yuxi-liu-wired wants to merge 3 commits into
logseq:masterfrom
yuxi-liu-wired:perf/open-codeed
Closed

yuxi-liu-wired wants to merge 3 commits into
logseq:masterfrom
yuxi-liu-wired:perf/open-codeed

Conversation

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor

The code editor module (:code-editor, CodeMirror and its modes) runs on every app open, though it is only needed when a code block is drawn. resources/index.html loads js/code-editor.js with a <script> tag; in a CPU profile of a desktop window reload it took about 360 ms of the renderer's time before the home screen.

frontend.components.lazy-editor already loads the module on demand (shadow.loader/load :code-editor when a code block mounts). In a release build the module loader resolves the module to /static/js/code-editor.js, the dev :asset-path, which does not exist beside a packaged index.html; the <script> tag hid that. The release build now uses :asset-path "./js", so the module is fetched from beside the page, and the tag is removed from index.html.

In a desktop release build the module loader table reads {"code-editor" ["./js/code-editor.js"]}, and a profile of a reload shows no code-editor.js work before the home screen.

yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 6, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 8, 2026
@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Fixed a real first-load code-block regression in 248a222.

Reproduced using the matching locally built nightly: create an empty block and type three backticks with real keyboard events. The language/copy shell appeared, but CodeMirror never mounted.

Root cause: Promesa's value factory wraps Shadow's Closure Deferred instead of awaiting its completion. Registration was checked before the module downloaded. The loader now explicitly resolves a Promesa promise from Shadow's completion callback and forwards its errback.

Validation sequence:

  • Added a real Closure Deferred test with delayed editor registration.
  • Unfixed code failed: Code editor module did not register its component.
  • Fixed code passed: 3 tests, 7 assertions.
  • Nightly renderer release compiled with zero warnings.
  • Clean UI verification (no manual evaluation/debugger interventions): three backticks mount CodeMirror; typing and selection work.
  • The same clean UI check still fails on the original local nightly.

The emergency fix is also on fork/main, with unfinished startup optimization excluded.

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Measured this optimization with ablations against upstream, using the same shared warm profile, Xvfb, hyperfine, 20 measured runs per build and CPU settings fixed at 100% with turbo enabled.

Whole-command mean ± standard deviation:

  • Upstream baseline: 2.819 ± 0.025 seconds.
  • Lazy translation compilation alone: 2.538 ± 0.026 seconds.
  • Lazy code editor alone: 2.664 ± 0.035 seconds.
  • Lazy MCP/updater dependencies alone: 2.717 ± 0.034 seconds.
  • Translation + code editor: 2.391 ± 0.032 seconds.
  • All three: 2.277 ± 0.017 seconds.
  • Our complete nightly: 2.285 ± 0.031 seconds.

The three changes together reproduce the full fork's startup performance. Launch-to-real-home for the three-change build: 2.077 ± 0.017 seconds versus upstream 2.621 ± 0.025 seconds. Code-block first use was checked using real keyboard events: three backticks mount CodeMirror; typing and selection work.

Ablation base: 22a29b3. Combined patch: d462a777b0. Raw benchmark JSON and per-run stages are retained locally at results/startup/20261008-190710, with individual-change comparisons at 20261008-185448, 20261008-185654, and 20261008-185902.

All three optimizations are already included in published fork-nightly commit 1771ba4. The lazy editor includes the module-registration completion fix.

yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 11, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 13, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
@yuxi-liu-wired
yuxi-liu-wired force-pushed the perf/open-codeed branch 5 times, most recently from abab695 to 3122e68 Compare October 22, 2026 11:01
@yuxi-liu-wired
yuxi-liu-wired force-pushed the perf/open-codeed branch 2 times, most recently from da7561f to bc7bb30 Compare October 25, 2026 11:01
yuxi-liu-wired and others added 3 commits October 26, 2026 04:00
The code editor module (`:code-editor`, CodeMirror and its modes) runs on every app open, though it is only needed when a code block is drawn. `resources/index.html` loads `js/code-editor.js` with a `<script>` tag; in a CPU profile of a desktop window reload it took about 360 ms of the renderer's time before the home screen.

`frontend.components.lazy-editor` already loads the module on demand (`shadow.loader/load :code-editor` when a code block mounts). In a release build the module loader resolves the module to `/static/js/code-editor.js`, the dev `:asset-path`, which does not exist beside a packaged `index.html`; the `<script>` tag hid that. The release build now uses `:asset-path "./js"`, so the module is fetched from beside the page, and the tag is removed from `index.html`.

In a desktop release build the module loader table reads `{"code-editor" ["./js/code-editor.js"]}`, and a profile of a reload shows no `code-editor.js` work before the home screen.
@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Combined into #13872 with the other PRs of this theme, to keep the number of open PRs down; the commits are unchanged there.

@yuxi-liu-wired
yuxi-liu-wired deleted the perf/open-codeed branch November 17, 2026 02:21
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