Relationships
↔ sibling #4902#4903 behavior validate re-scans models/ once per distinct expression model reference (O(references x definition files) file opens)
Opened by zack · 11/19/2026· Shipped 11/19/2026
Summary
swamp behavior validate (with no name, so every definition is validated) re-reads the definition files under models/ once for each distinct behavior referenced from an expression. validateAll in src/libswamp/models/validate.ts first lists every definition with findAllGlobal. Then, for each definition, DefaultModelValidationService resolves every model.<name> reference by calling definitionRepo.findByNameGlobal (validateModelPathReference and namesModel in src/domain/models/validation_service.ts, around lines 1189 and 1285). In the CLI no name index is attached, and the findAllGlobal walk records no name hints. So each name new to the process walks models/ in sorted order, parsing YAML until it matches. Cost is O(distinct referenced behaviors x definition files), though the full listing at the start has already parsed every file once. This has the same shape as swamp-club#4895 (fixed for behavior search --json) and swamp-club#4902 (workflow validate/run).
Measurements
Scratch repo: 500 command/shell definitions (s000..s499). Each has run: echo followed by a model.sNNN.definition.globalArguments expression that references one other definition, spread across the 500. Every definition validates cleanly. Counted successful openat calls on models/**/*.yaml with strace -f -e trace=openat, using swamp 20261118.223849.0-sha.c2530f0f:
| Command | models/ YAML opens | Wall time |
|---|---|---|
swamp behavior validate --json, definitions cross-referencing |
125,750 | 3.9s |
swamp behavior validate --json, same 500 definitions without references |
500 | |
swamp behavior validate s250 --json (single, one reference) |
~1,000 |
That is about 250 reads per file: one partial walk per distinct reference.
Reproduction
swamp repo initin an empty directory.- Create 500
command/shelldefinitionss000..s499undermodels/command/shell/. Give each amethods.execute.arguments.runwhose expression references a different definition (for examplemodel.s261.definition.globalArgumentsinside the usual expression braces). strace -f -e trace=openat -o ol.log swamp behavior validate --json >/dev/null, then count lines matching/models/.*\.yaml"(excluding ENOENT). Compare with the same repo after removing the references.
Expected
Validating every definition should read each definition file about once. The full listing validateAll already does holds every definition, so reference checks can be answered from it, or from a name index built during that walk.
Possible directions
- Answer reference lookups during
validateAllfrom thefindAllGlobalresult (a name map), or have that walk record a name hint for every file it parses, so each laterfindByNameGlobalis a single read. - A shared CLI-side name index would also cover swamp-club#4902.
Shipped
Click a lifecycle step above to view its details.