Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance issues during loading the template #340

Open
Spasenie-Brest opened this issue May 19, 2023 · 1 comment
Open

Performance issues during loading the template #340

Spasenie-Brest opened this issue May 19, 2023 · 1 comment

Comments

@Spasenie-Brest
Copy link

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

@Spasenie-Brest
Copy link
Author

@krzysztofzablocki @djbe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant