lietzsche;noether
Pages

updated 2026-11-26·2 min read

Optimizing Extension Load Time

Keep Noether startup responsive with dynamic imports for heavy libraries, Web Worker offloading, debounced SQLite writes, and performance.now() benchmarking.

If your extension blocks the main thread inside onload(), Noether’s cold boot drags for every user who installs it. Keep startup quick with lazy imports, off-thread workers, and debounced SQLite writes.

1. Lazy-Loading Heavy Dependencies

Never import heavy third-party libraries (such as PDF parsers, charting engines, or LaTeX renderers) at the top level of your entry file:

// ❌ Slower: Evaluates the heavy bundle immediately on Noether boot
import * as Papa from 'papaparse';

export default class CsvExporterExtension extends Extension {
  async onload() {
    this.addCommand({
      id: 'export-csv',
      title: 'Export Table as CSV',
      action: () => {
        Papa.unparse(...);
      }
    });
  }
}

Instead, dynamically import modules when the user actually triggers the action:

// ✅ Optimized: Zero startup overhead
export default class CsvExporterExtension extends Extension {
  async onload() {
    this.addCommand({
      id: 'export-csv',
      title: 'Export Table as CSV',
      action: async () => {
        const Papa = await import('papaparse');
        Papa.unparse(...);
      }
    });
  }
}

2. Offloading to the Web Worker Pool

If your extension needs to perform computationally intensive calculations (such as computing graph layouts, generating semantic embeddings, or indexing thousands of blocks), offload the work to Noether’s Web Worker thread pool:

// Execute heavy work off the UI thread inside an Extension method
const result = await this.runTask(
  'heavy-indexing',
  { documentIds },
  { priority: 'background', timeoutMs: 10000 }
);

This keeps heavy computation off the main thread so typing and navigation remain smooth. Learn more in Noether SDK API Reference.

3. Debouncing Database Writes

When your extension listens to document:saved events to update custom metadata, avoid executing redundant SQLite writes on rapid consecutive saves. Keep an in-memory state representation and debounce database persistence:

import { Extension } from 'noether';

export default class WordCounterExtension extends Extension {
  private saveDebounceTimer: number | null = null;

  async onload() {
    this.registerEvent(
      this.app.events.on('document:saved', ({ id, title }) => {
        this.updateMemoryStats(id, title);

        if (this.saveDebounceTimer !== null) {
          window.clearTimeout(this.saveDebounceTimer);
        }
        this.saveDebounceTimer = window.setTimeout(() => {
          this.flushStatsToDatabase(id);
        }, 500);
      })
    );
  }
}

4. Measuring Load Time

You can benchmark your extension’s activation time inside onload():

async onload() {
  const start = performance.now();

  // Initialization logic...

  const elapsed = performance.now() - start;
  if (elapsed > 30) {
    console.warn(`[Performance] Extension onload took ${elapsed.toFixed(2)}ms`);
  }
}

For more architectural best practices, read Micro-Kernel & Core Isolation and Developer Policies & Guidelines.

Search wiki and portfolio

type to search across all entries.