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

Refactor how location of nodes are calculated. #703

Merged
merged 3 commits into from
Nov 14, 2024

Conversation

gdotdesign
Copy link
Member

Source map generation triggered this refactor, but it was on my radar for a while.

The location calculation was previously done on demand, which meant that it was a performance problem because it iterates over the lines of the source files many times. It wasn't an issue before because only the language server was using it, but now with the source maps it presented an opportunity for refactoring.

In the new version, the parser keeps track of the location during parsing. Positions of AST nodes now include the line and column along with the offset (that's why all node files changed).

Now, source map generation time is down and parsing time don't seem to be affected (subject project mint-website).

Without refactor
Parsing: 295.385ms
Source map generation: 891.879ms

Refactor
Parsing: 267.674ms
Source map generation: 176.489ms

@gdotdesign gdotdesign added the enhancement New feature or request label Nov 12, 2024
@gdotdesign gdotdesign added this to the 0.21.0 milestone Nov 12, 2024
@gdotdesign gdotdesign self-assigned this Nov 12, 2024
@gdotdesign gdotdesign requested a review from Sija November 12, 2024 15:52
src/ast.cr Outdated Show resolved Hide resolved
src/ast/node.cr Outdated Show resolved Hide resolved
src/ast/node.cr Outdated Show resolved Hide resolved
src/ast/node.cr Outdated Show resolved Hide resolved
src/compilers/suite.cr Outdated Show resolved Hide resolved
src/ls/folding_range.cr Outdated Show resolved Hide resolved
src/parser.cr Outdated Show resolved Hide resolved
Instead of calculating the location (line, column) of a node after the fact it is now part of the parser.
@gdotdesign gdotdesign force-pushed the node-location-refactor branch from 1461d23 to 3037cd1 Compare November 13, 2024 09:17
@gdotdesign gdotdesign requested a review from Sija November 13, 2024 17:01
src/ast/node.cr Outdated Show resolved Hide resolved
src/parser.cr Outdated Show resolved Hide resolved
src/parser/location.cr Outdated Show resolved Hide resolved
gdotdesign and others added 2 commits November 14, 2024 21:17
Co-authored-by: Sijawusz Pur Rahnama <sija@sija.pl>
@gdotdesign gdotdesign requested a review from Sija November 14, 2024 20:29
Copy link
Member

@Sija Sija left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@gdotdesign gdotdesign merged commit 8a72288 into master Nov 14, 2024
2 of 3 checks passed
@gdotdesign gdotdesign deleted the node-location-refactor branch November 14, 2024 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

2 participants