Skip to content

perf(cli): avoid eager API imports - #146

Merged
Paul-Kyle merged 1 commit into
phasespace-labs:mainfrom
WilliamK112:fix/lazy-cli-api-imports
Aug 23, 2026
Merged

perf(cli): avoid eager API imports#146
Paul-Kyle merged 1 commit into
phasespace-labs:mainfrom
WilliamK112:fix/lazy-cli-api-imports

Conversation

@WilliamK112

Copy link
Copy Markdown
Contributor

Summary

  • import the Obsidian wiki-footer helper directly from its core definition instead of through palinode.api.server
  • move _MEMORY_CATEGORY_DIRS beside _TYPE_TO_CATEGORY in palinode.core.memory_write, while preserving the historical API re-export
  • add a subprocess regression proving a plain palinode.cli import loads neither FastAPI nor palinode.api.server

Fixes #143.

Import-time measurement

Measured with Python 3.11 using five fresh post-warmup subprocesses per revision:

PYTHONPATH=. python -X importtime -c "import palinode.cli"
  • before: median cumulative palinode.cli import time 331 ms (323-367 ms)
  • after: median cumulative palinode.cli import time 188 ms (187-210 ms)
  • change: 143 ms / 43% lower median cumulative import time

Before this change, the trace included palinode.api.server (about 78-81 ms cumulative in the measured runs). After the change, that module is absent; a direct module check also reports both fastapi and palinode.api.server as unloaded.

Validation

  • focused import/Obsidian/frontmatter/wiki-footer tests: 99 passed
  • complete suite: 3130 passed, 10 skipped, 5 xfailed
  • ruff check palinode/ tests/ scripts/
  • bandit -r palinode/ -ll
  • git diff --check

AI assistance disclosure: I used OpenAI Codex to help inspect the import graph, implement the scoped change, run measurements, and validate the patch. I reviewed the final diff and evidence before submitting.

Import the wiki footer and category maps from their core definitions so ordinary CLI startup does not initialize FastAPI or the provenance UI. Keep the historical API re-export intact and add an isolated subprocess regression for the import boundary.

Signed-off-by: WilliamK112 <164879897+WilliamK112@users.noreply.github.com>
@Paul-Kyle
Paul-Kyle merged commit 4f81b8c into phasespace-labs:main Aug 23, 2026
9 checks passed
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.

palinode --help imports the entire FastAPI app before running any command

2 participants