HomeVyOS Platform

rm_templates: T8609: fix slow parse() from group-quantifier patterns
71af7b82a6faUnpublished

Unpublished Commit ยท Learn More

  • Publishing Disabled: All publishing is disabled for this repository.
  • Not On Permanent Ref: This commit is not an ancestor of any permanent ref.
This commit no longer exists in the repository. It may have been part of a branch which was deleted.This commit has been deleted in the repository: it is no longer reachable from any branch, tag, or ref.

Description

rm_templates: T8609: fix slow parse() from group-quantifier patterns

Three related quantifier shapes across nine rm_templates files caused
O(2^n) regex backtracking in vyos_route_maps and related resource
modules. parse() time on a representative 12-line config drops from
~50s to <1ms.

  • Trailing form (188 sites): (?P<X>\S+)\n *$""" -> (?P<X>\S+)\s*$""". Under re.VERBOSE the literal newline+ spaces between \S+ and *$ is stripped at compile time, so the source compiled to (\S+)*$ with the * quantifying the named group.
  • Mid-pattern (group containing \S+)* (22 sites in snmp_server.py with a couple in bgp_global*.py): e.g. (?P<protocol>protocol\s\S+)* -> (?P<protocol>protocol\s\S+)?. Different position from the trailing form, but the same shape underneath (a group whose content includes \S+, quantified with *), so the same O(2^n) backtracking on prefix-sharing inputs.
  • Mid-pattern (literal-only group)* (14 sites in snmp_server.py, bgp_address_family*.py, bgp_global*.py): e.g. (?P<as_set>as-set)* -> (?P<as_set>as-set)?. No \S+ inside the quantified group, so the backtracking exposure is much smaller. On the inputs these patterns actually receive (no device line carries duplicate flags) * and ? accept identical input sets, so changing to ? is behavior-preserving.

Affects: route_maps[/_14], bgp_global[/_14], bgp_address_family[/_14],
snmp_server, ospf_interfaces[/_14].

Adds a perf regression test (test_rm_templates_perf.py) with a 1-second
budget against fixture inputs that have realistic-length identifiers;
without the fix the existing 18-line unit fixtures still parse fast
enough to mask the regression.

Details

Provenance
cr0ntabAuthored on May 1 2026, 4:49 PM

Event Timeline

Commit No Longer Exists

This commit no longer exists in the repository.