vlan: answer membership questions without re-parsing an allowed list (#1809) #1812

Merged
jaylouisw merged 1 commit from fix/1117-0805 into main 2026-11-17 08:12:40 +00:00
Owner

Fixes #1809.

What was wrong. switchport trunk allowed vlan remove 2 on a default trunk leaves 4,089 ids in allowedVlans. classifyEgress() normalises the port config and then asks vlanListIncludes() about one id � and both calls ran the full parseVlanList() tokeniser (string conversion, regex per entry, sort) over the whole array. One bit of information cost ~1.3 ms, so 2,000 calls took 2,445 ms locally; #1749 measured 6,063-6,510 ms in CI at PF_TEST_CONCURRENCY=10.

The issue names an identity-keyed memberCache; there is no such cache on main � the cost is the two unconditional parses per call, which is the same defect and wants the same fix: stop re-deriving a list that is already in canonical form.

What changed (engine/vlan.js, no exported surface changed):

  • isCanonicalVlanArray() recognises a list whose entries are integers, in range, none of the reserved block, strictly ascending � i.e. exactly what parseVlanList() would return for it. One pass of integer comparisons.
  • normalizePortConfig() copies such a list instead of parsing it. The copy is kept, so the returned config still owns its array and a caller cannot edit the input through it.
  • vlanListIncludes() binary-searches such a list instead of parsing it.
  • Everything else � unsorted, duplicated, string entries, reserved or out-of-range ids, 'all' � still goes through parseVlanList() and keeps its exact meaning.

Measured (same host, 4,089 ids): 2,445 ms ? 35 ms for 2,000 classifyEgress() calls; 37-58 ms across ten concurrent processes.

Tests. New test/vlan-membership-lookup.test.js, 18 assertions: the fast path agrees with a full parse for every id 1-4094, non-canonical lists keep their parsed meaning, normalizePortConfig() copies rather than aliases, and the 2,000-call bound (#1749 uses 3,000 ms; this asserts 1,500 ms).

Gates: node scripts/syntax-check.js 380 files OK; check-control-bytes clean; full npm test 309 suites, 10,776 assertions, 0 failed.

Once merged, #1749 should go green on rebase � its data is not the problem.

Co-authored-by: Hermes Agent jay@jayw.uk

Fixes #1809. **What was wrong.** `switchport trunk allowed vlan remove 2` on a default trunk leaves 4,089 ids in `allowedVlans`. `classifyEgress()` normalises the port config and then asks `vlanListIncludes()` about one id � and both calls ran the full `parseVlanList()` tokeniser (string conversion, regex per entry, sort) over the whole array. One bit of information cost ~1.3 ms, so 2,000 calls took 2,445 ms locally; #1749 measured 6,063-6,510 ms in CI at `PF_TEST_CONCURRENCY=10`. The issue names an identity-keyed `memberCache`; there is no such cache on `main` � the cost is the two unconditional parses per call, which is the same defect and wants the same fix: stop re-deriving a list that is already in canonical form. **What changed** (`engine/vlan.js`, no exported surface changed): - `isCanonicalVlanArray()` recognises a list whose entries are integers, in range, none of the reserved block, strictly ascending � i.e. exactly what `parseVlanList()` would return for it. One pass of integer comparisons. - `normalizePortConfig()` copies such a list instead of parsing it. The copy is kept, so the returned config still owns its array and a caller cannot edit the input through it. - `vlanListIncludes()` binary-searches such a list instead of parsing it. - Everything else � unsorted, duplicated, string entries, reserved or out-of-range ids, `'all'` � still goes through `parseVlanList()` and keeps its exact meaning. **Measured** (same host, 4,089 ids): 2,445 ms ? 35 ms for 2,000 `classifyEgress()` calls; 37-58 ms across ten concurrent processes. **Tests.** New `test/vlan-membership-lookup.test.js`, 18 assertions: the fast path agrees with a full parse for every id 1-4094, non-canonical lists keep their parsed meaning, `normalizePortConfig()` copies rather than aliases, and the 2,000-call bound (#1749 uses 3,000 ms; this asserts 1,500 ms). Gates: `node scripts/syntax-check.js` 380 files OK; `check-control-bytes` clean; full `npm test` 309 suites, 10,776 assertions, 0 failed. Once merged, #1749 should go green on rebase � its data is not the problem. Co-authored-by: Hermes Agent <jay@jayw.uk>
vlan: answer membership questions without re-parsing an allowed list (#1809)
All checks were successful
PR rebase / Rebase onto main and arm auto-merge (pull_request) Successful in 6s
CI / Classify the change (pull_request) Successful in 8s
CI / Server smoke test (pull_request) Successful in 8s
CI / Docker build (pull_request) Successful in 22s
CI / Test (Node 20) (pull_request) Successful in 49s
CI / Test (Node 18) (pull_request) Successful in 56s
CI / Test (Node 22) (pull_request) Successful in 52s
CI / Arm auto-merge (pull_request) Successful in 12s
07d2ecf82a
A trunk built by `switchport trunk allowed vlan remove 2` allows 4,089 ids.
normalizePortConfig() and vlanListIncludes() each ran the full parseVlanList()
tokeniser over that array on every classifyEgress()/classifyIngress() call, so
one yes/no question cost ~1.3 ms and 2,000 of them took 2.4 s locally (#1749
sees 6 s in CI).

A list that is already canonical - integers, in range, none reserved, strictly
ascending - now takes a comparison pass: normalizePortConfig() copies it without
parsing it, and vlanListIncludes() binary-searches it. Everything else
(unsorted, duplicated, string entries, reserved or out-of-range ids, 'all')
still goes through parseVlanList() and keeps its exact meaning.

The 4,089-id loop drops from 2,445 ms to 35 ms. test/vlan-membership-lookup.test.js
pins the agreement between the fast path and a full parse for every id 1-4094,
the copy-not-alias contract, and the 2,000-call bound.

Co-authored-by: Hermes Agent <jay@jayw.uk>
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jaylouisw/packetforge!1812
No description provided.