Skip to content

parse() runs several whole-log regex scans - ~7× slower than needed #32

Description

@Malkiz223

Every parse() call makes a handful of full-log regex passes - a per-line search for each of the 9 latest-match patterns, a whole-log re.findall per log-category, and PATTERN_LOG_ENDING / scrape-item scans from the start - even though each one only needs a small, locatable slice of the log. On large logs this dominates the runtime.

They can all be narrowed with cheap literal checks (in / str.find, C-level) without changing the output - the regex still decides every match, and the literal only decides whether it's worth running. Measured (CPython 3.12):

lognowpatchedspeedup
142 KB13.7 ms1.8 ms7.6×
1.1 MB108 ms15 ms7.3×
10 MB896 ms126 ms7.1×
1.1 MB (many error/retry/redirect lines)98 ms14 ms7.2×

Output is byte-identical and the existing test suite passes unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions