Project Stage: Prototype - Exploring structure, algorithms, and implementation. Everything is subject to change.
The standard Zig parser is no slouch,
but it’s a full-document parser — reprocessing the entire document from scratch for every edit.
This becomes inefficient for frequent small edits, which this project aims to address through targeted optimizations.
NOTE: Uplift numbers are based on small edits. Performance may vary for large-scale changes.
-
G1: Reuse tokens
Achieves ~50% uplift (relatively flat latency regardless of edit location)
-
G2: Reuse root declarations (part 1)
Reuse root declarations before the edit point, with performance gains increasing toward document end. Achieves G1 + 0–45% uplift
-
G3: Reuse root declarations (part 2)
Reuse as many root declarations as possible. Increased complexity (calculations/viability checks, 2 extra allocations, replace nodes range, shift indices) may lower G2’s uplift but provides a more consistent ~30–45% uplift over G1 across all edit locations
-
G4: Parse only affected nodes
High complexity. Aims to ensure flat latency across all edit locations for a G1 + 40% total uplift.
-
Specialized AstCheck component
-
Early Exit Support: Checks a thread-safe flag,
change_pending: *std.atomic.Value(bool),
early ingenerate()and in thecontainer_decl.ast.membersloop instructDeclInner() -
-= IMPORTANT =- Given that
AstCheck.generate()may return early,
The.instructionsfield of the AstCheck result should always be treated as undefined
Given that AstCheck shouldn't be called when ast.errors.len != 0, the cases that benefit are:
- rapidly inserting new lines
- modifying existing identifiers, ie edits that don't introduce parse errors
- distant third: ast-check errors past the 50% mark of a large document
-
Take a tailored version of ZLS for a spin and discover if it enhances your editing experience
Keep in Mind:
Half (50%) of a small number, is an even smaller number — for tiny files or on capable hardware, the speed-up might be imperceptible.
Suggested Test Files:
- Your own project files / files you are familiar with
- https://github.com/ziglang/zig/blob/master/src/Sema.zig
- https://github.com/ziglang/zig/blob/master/src/codegen/x86_64/CodeGen.zig
(will stress test your editor as well)
This project is licensed under the MIT License.
It includes large portions of code from Zig, which is also released under the MIT License.