Skip to content

Performance Issue: Regex recreated for each line of parsed file #52

@Adobels

Description

@Adobels

The prettyPrintVersions function iterates over each line of an input file, which can contain up to 30,000 lines as Today.
Currently, within each iteration, a new regex object is created at FileUtilities.swift:107:
if line.contains(/"implementationVersions" :/) {

Proposed Improvements

  1. Precreate the regex

Define the regex as a let before the loop, then reuse it within the for-in iteration instead

  1. Use contain with a substring not regex (optional)
    The same result can be achieved with String.contains(:)_ for the string "implementationVersions :". If this approach is retained, let constant from the point 1 can be defined as a string literal instead of regex literal.

The improvements can reduce the parsing of the input content from seconds to milliseconds for the function in questions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions