Skip to content

perf(lockfile): compose the generator check on libyaml events - #5408

Merged
Daniel Meppiel (danielmeppiel) merged 2 commits into
mainfrom
danielmeppiel-perf-lock-gate-once
Nov 25, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 2 commits into
mainfrom
danielmeppiel-perf-lock-gate-once

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Description

The lockfile generator gate (lockfile_generator._inspect -> yaml_io.top_level_scalar_values) composes the whole apm.lock.yaml with the pure-Python bounded loader just to read the top-level apm_version declarations. 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 _BoundedCSafeLoader uses 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 way LockFile.read reads 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

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

tests/unit/utils/test_machine_yaml.py:

  • test_the_generator_check_reads_what_the_pure_parser_or_the_reader_reads is 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_scanner checks 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

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit: docs/src/content/docs/specs/openapm-v0.1.md updated
    (new/changed <a id="req-XXX"></a> anchor + prose + Appendix C
    row).
  • Manifest edit: docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.yml
    updated.
  • Test edit: a @pytest.mark.req("req-XXX") test under
    tests/spec_conformance/ added or extended.
  • CONFORMANCE.{md,json} regenerated via
    uv run --extra dev python -m tests.spec_conformance.gen_statement
    and committed.
  • N/A -- this PR does not change OpenAPM-observable behaviour.

apm-spec-waiver: performance-only change; the gate reads the lockfile with the reader's scanner

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>

Copilot AI left a comment

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.

🟡 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

Comment thread src/apm_cli/utils/yaml_io.py Resolved
Comment thread tests/unit/utils/test_machine_yaml.py Resolved
…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>

Copilot AI left a comment

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.

🟢 Approval recommended

No active review issues remain for the lockfile generator-check optimization.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

@danielmeppiel Daniel Meppiel (danielmeppiel) added full-integration Run the full integration suite (ci-integration.yml) on this PR before merge and removed full-integration Run the full integration suite (ci-integration.yml) on this PR before merge labels Nov 25, 2026
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit a7ba3b0 into main Nov 25, 2026
73 of 89 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-perf-lock-gate-once branch November 25, 2026 06:56
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