Repository navigation
perf(lockfile): compose the generator check on libyaml events - #5408
Merged
Daniel Meppiel (danielmeppiel) merged 2 commits intoNov 25, 2026
Merged
Conversation
The generator gate (lockfile_generator._inspect -> top_level_scalar_values) composed the whole apm.lock.yaml with the pure-Python bounded loader just to read the top-level apm_version declarations. It now composes on libyaml's scanner and parser with the same Python composer and bounded loader that #5361 uses for lockfile reads. Text with a tab, text over the machine-YAML budget, and anything the C parser cannot compose fall back to the pure parser, so the verdict is the pure parser's. Refs #4939 apm-spec-waiver: performance-only change; the generator verdict is identical to the pure parser's Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Daniel Meppiel (danielmeppiel)
requested a review
from Sergio Sisternes (sergio-sisternes-epam)
as a code owner
November 24, 2026 23:51
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The fast path can accept lockfiles the pure parser rejects when ? appears in a flow scalar, and a C-specific test fails on supported installations without libyaml.
2 open issues
What changed in this PR
This PR targets lockfile generator-check overhead as part of #4939’s install-performance work, using libyaml scanning and parsing with the existing Python composer.
Changes:
- Adds accelerated composition with pure-Python fallback for tabs, over-budget input, and C-parser failures.
- Adds differential coverage for lockfile fixtures and edge cases, plus a scanner-use assertion.
| File | Description |
|---|---|
tests/unit/utils/test_machine_yaml.py |
Adds parser-equivalence cases and an acceleration-path check. |
src/apm_cli/utils/yaml_io.py |
Adds libyaml-backed composition to top-level scalar inspection. |
Review effort: Balanced
…C-only cell without libyaml Copilot found a second text libyaml accepts and the pure scanner refuses (`?` inside a flow scalar). On text both scanners accept the composed graph is identical; text only libyaml accepts is now read as the lockfile reader (libyaml since #5361) reads it. Tab text keeps the pure scanner. The differential cell pins exactly that, and the no-pure-scanner cell skips on PyYAML without libyaml. Refs #4939 apm-spec-waiver: performance-only change; the gate reads the lockfile with the reader's scanner Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Merged
1 task done
Daniel Meppiel (danielmeppiel)
deleted the
danielmeppiel-perf-lock-gate-once
branch
November 25, 2026 06:56
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.


Description
The lockfile generator gate (
lockfile_generator._inspect->yaml_io.top_level_scalar_values) composes the wholeapm.lock.yamlwith the pure-Python bounded loader just to read the top-levelapm_versiondeclarations. It needs the composed graph, not a load, so it can see duplicate keys and flow style. On a t50 install that pure compose is the largest lockfile cost on the no-op path. In a paired deletion on top of #5383, removing the gate entirely gives install-noop L 0.842.It now composes on libyaml's scanner and parser, using the same Python composer
_BoundedCSafeLoaderuses for every lockfile read since #5361. Text that both scanners accept gives an identical node graph, so duplicate keys, flow style, merge keys, null and non-scalar values are judged exactly as before. Text that only libyaml accepts (for example?inside a flow scalar) is now read the wayLockFile.readreads it, so the gate and the reader agree. On the entry gate this can only add a refusal. Text with a tab, text over the machine-YAML budget, and anything libyaml cannot compose still go through the pure parser.Cost: one libyaml scan/parse plus a Python compose per distinct lockfile text, memoized as before. Cost is unchanged when a case falls back.
Bench vs merge-base bb4744f, t50, 6 pairs, paired CPU new/base: no-op Linux 0.931 [45513339268], Windows 0.977 [45513377638]; cold and warm are neutral (L 0.991/1.003, W 1.006/1.002). Requests identical, 0 errors.
Issue and approved scope
Issue: Refs #4939
Human scope-approval comment: install performance work under the approved #4939 perf scope (standing PERF approval for groundbreaking performance work).
#4939 continues.
Type of change
Testing
tests/unit/utils/test_machine_yaml.py:test_the_generator_check_reads_what_the_pure_parser_or_the_reader_readsis a differential against the pure compose; for text only libyaml accepts, it checks against the reader's libyaml compose instead. It covers every lockfile fixture plus edge cases: absent, duplicate, flow, null, non-scalar, merge key, not a mapping, empty, malformed, tab, BOM and unicode, alias value and alias key, a huge plain scalar, CRLF, NUL, a directive, two documents, and the alias, merge, huge-int and deep-nesting bombs, and?inside a flow scalar.test_an_admitted_lockfile_is_composed_without_the_pure_scannerchecks that the pure scanner is never engaged for an admitted lockfile.Local guarded run:
pytest -q -p no:xdist tests/unit/utils/test_machine_yaml.py tests/unit/deps -k "generator or machine or composed": 745 passed. Bench at this head vs merge-base bb4744f (L/W, t50 cold/warm/noop, 6 pairs) follows as a comment.Changelog
changelog.d/<pr>.<section>.md, holdingone line: user-visible effect first, 25 words or fewer, ending with
(#PR); breaking changes only under upgrade notes; no Highlights; nonew lines under
## [Unreleased]. Seechangelog.d/README.mdand.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
docs/src/content/docs/specs/openapm-v0.1.mdupdated(new/changed
<a id="req-XXX"></a>anchor + prose + Appendix Crow).
docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.ymlupdated.
@pytest.mark.req("req-XXX")test undertests/spec_conformance/added or extended.CONFORMANCE.{md,json}regenerated viauv run --extra dev python -m tests.spec_conformance.gen_statementand committed.
apm-spec-waiver: performance-only change; the gate reads the lockfile with the reader's scanner