Skip to content

perf: speed up slow -c startup by compiling YANG schema once#38

Open
Shbinging wants to merge 1 commit into
holo-routing:mainfrom
Shbinging:perf-compile-yang-once
Open

perf: speed up slow -c startup by compiling YANG schema once#38
Shbinging wants to merge 1 commit into
holo-routing:mainfrom
Shbinging:perf-compile-yang-once

Conversation

@Shbinging

@Shbinging Shbinging commented Jul 13, 2026

Copy link
Copy Markdown

Every holo-cli -c invocation loads the ~75 YANG modules holod advertises. libyang recompiles the whole context after each load_module(), so startup does ~75 full recompilations of a growing schema — an O(n²) cost that makes every -c command very slow: the load loop alone takes ~512 ms, dominating the ~0.51 s wall clock.

Create the context with LY_CTX_EXPLICIT_COMPILE, load all modules (parse only), then compile once:

  • load loop: ~512 ms → ~22 ms
  • compile: one ~38 ms pass
  • total: ~0.51 s → ~0.07 s (~7x)

Output is unchanged.

@Shbinging
Shbinging force-pushed the perf-compile-yang-once branch 3 times, most recently from 3a7e49b to 8b204d6 Compare July 13, 2026 08:19
@Shbinging Shbinging changed the title perf: compile YANG schema once instead of after every module load perf: speed up slow -c startup by compiling YANG schema once Jul 13, 2026
Comment thread src/main.rs
//
// yang5 0.2 exposes neither a safe `compile()` wrapper nor a `from_raw()`
// constructor, so the compiled schema has to be triggered through the raw
// libyang pointer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to open a PR for the yang5 crate to implement that.

Every holo-cli invocation builds a fresh libyang context by calling
`load_module()` for each module holod advertises (~75). libyang compiles the
entire context after each `load_module()` by default, so startup does ~75
successive full recompilations of a growing schema — an O(n^2) cost that
dominates one-shot latency. Profiling `holo-cli -c "show state format json"`
against a live holod:

    connect              ~0.2 ms
    capabilities RPC     ~0.3 ms
    load_module loop     ~512 ms   <-- here
    gen_cmds             ~0.8 ms
    Session::new         ~1.4 ms
    total wall clock     ~0.51 s

This is paid on every `-c` call; FlowDiff spawns holo-cli 7-8 times per step
(800+ per test case), making it the dominant end-to-end cost.

Create the context with `LY_CTX_EXPLICIT_COMPILE`, load all modules (parse
only), then compile the whole schema in a single pass. The module-load loop
drops from ~512 ms to ~22 ms plus a ~38 ms one-shot compile:

    load_module loop     ~22 ms
    compile once         ~38 ms
    total wall clock     ~0.07 s   (~7x faster)

Output is unchanged: the schema is fully compiled before gen_cmds and any data
retrieval/parsing runs. This also speeds up interactive startup, so it's
applied unconditionally rather than gated on `-c`.

Note: passing multiple `-c` flags to a single invocation already reuses one
process, one gRPC connection and one loaded/compiled schema (main() loops over
the commands), so batching dumps amortizes even this reduced cost.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Shbinging
Shbinging force-pushed the perf-compile-yang-once branch from 8b204d6 to 7be637b Compare July 13, 2026 08:39
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.

2 participants