perf: speed up slow -c startup by compiling YANG schema once#38
Open
Shbinging wants to merge 1 commit into
Open
perf: speed up slow -c startup by compiling YANG schema once#38Shbinging wants to merge 1 commit into
Shbinging wants to merge 1 commit into
Conversation
Shbinging
force-pushed
the
perf-compile-yang-once
branch
3 times, most recently
from
July 13, 2026 08:19
3a7e49b to
8b204d6
Compare
sha90w
reviewed
Jul 13, 2026
| // | ||
| // 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. |
Contributor
There was a problem hiding this comment.
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
force-pushed
the
perf-compile-yang-once
branch
from
July 13, 2026 08:39
8b204d6 to
7be637b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Every
holo-cli -cinvocation loads the ~75 YANG modules holod advertises. libyang recompiles the whole context after eachload_module(), so startup does ~75 full recompilations of a growing schema — an O(n²) cost that makes every-ccommand 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:Output is unchanged.