Commit 53740cb
committed
perf(converter): lazy-import markitdown to cut startup and enable slim packaging
markitdown is only used for the non-PDF, non-Markdown ingest branch, but it
was imported at module top level — so every `import openkb` eagerly pulled in
markitdown → magika → onnxruntime (tens of MB, slow). Move the import into the
branch that actually uses it.
Effects (measured):
- `import openkb.cli` cold start 4.64s → 3.53s (~24% faster); magika /
onnxruntime / markitdown no longer load unless an Office-format document is
converted.
- A packaged (PyInstaller) build can now exclude magika/onnxruntime for a
slimmer artifact when Office-format ingest isn't needed. Previously the
unconditional module-level markitdown import made magika load-bearing at
startup, so excluding it crashed the whole app on launch.
markitdown appends warning filters on import but leaves the CLI's front
"ignore" filter at index 0, so no re-suppression is needed at the new import
site. test_converter patches `markitdown.MarkItDown` (the real attribute the
local import binds) instead of the removed `openkb.converter.MarkItDown`.
Claude-Session: https://claude.ai/code/session_01KZyUSGAzVL9yxpsWWPv6Y21 parent 7cde496 commit 53740cb
2 files changed
Lines changed: 10 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
230 | 229 | | |
231 | 230 | | |
232 | 231 | | |
233 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
234 | 241 | | |
235 | 242 | | |
236 | 243 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
145 | 145 | | |
146 | 146 | | |
147 | 147 | | |
148 | | - | |
| 148 | + | |
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| |||
0 commit comments