Skip to content

Performance issues during loading the template #340

@Spasenie-Brest

Description

@Spasenie-Brest

I have dozen template and hundreds calls of Sorcery to generate the code, some of templates execute slowly and I try to find the issue. What I found, 150lines template spends 2+ sec to be loaded, after research I found an issue:

Zrzut ekranu 2023-05-19 o 16 01 32

self.lines = zip(1..., templateString.components(separatedBy: .newlines)).compactMap { index, line in
    guard !line.isEmpty,
      let range = templateString.range(of: line) else { return nil }
    return (content: line, number: UInt(index), range)
  }

Range(of) is not light operations, it scans origin text from the beginning on each step to find the current line.
I think we can improve it, as range(of:) does have additional param searchRange: Range<Self.Index>? = nil

So we can remember previous found range and use it to set searchRange

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