mirror of
https://codeberg.org/ziglang/zig
synced 2026-11-18 07:05:05 +00:00
AstGen: fix O(N^2) perf for many decls with same parent
AstGen was calling findLineColumn() for every sibling Decl, using the parent Decl as the starting point for the search for newlines. This resulted in poor performance for large numbers of Decls with the same parent. The solution is simple: since AstGen progresses monotonically through the AST, keep a single cursor into the source file, and whenever line/column information is needed, advance the cursor. This guarantees O(N) on the number of bytes in the file. Perf: As an example I ran ast-check on zigwin32/win32/everything.zig (a 17 MiB file) in master branch, and after this commit. With master branch, I killed the process after 17 seconds out of boredom. With this commit, it completed in 300 milliseconds. Closes #9234
This commit is contained in:
parent
49b3986417
commit
73f77f3080
1 changed files with 50 additions and 18 deletions
Loading…
Add table
Add a link
Reference in a new issue