You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
self.lines =zip(1..., templateString.components(separatedBy:.newlines)).compactMap{ index, line inguard !line.isEmpty,let range = templateString.range(of: line)else{returnnil}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
The text was updated successfully, but these errors were encountered:
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:
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 paramsearchRange: Range<Self.Index>? = nil
So we can remember previous found range and use it to set searchRange
The text was updated successfully, but these errors were encountered: