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

Migrate parsing to YARP #227

Merged
merged 4 commits into from
Sep 7, 2023
Merged

Migrate parsing to YARP #227

merged 4 commits into from
Sep 7, 2023

Conversation

Morriar
Copy link
Collaborator

@Morriar Morriar commented Sep 5, 2023

I've been experimenting with different parser backends to benchmark RBI parsing.

Here are the time required to parse all the 11801 RBI files in on big project:

Backend Parsing Time
Whitequark 288s
SyntaxTree 548s
YARP 22s

This PR migrates RBI parsing to YARP and removes the dependecy to Whitequark and unparser.

Running tapioca check-shims before (using parser gem):

Loading Sorbet payload...  Done (3.72s)
Loading shim RBIs from sorbet/rbi/shims... Done (0.97s)
Loading gem RBIs from sorbet/rbi/gems...  Done (204.15s)
Loading dsl RBIs from sorbet/rbi/dsl...  Done (69.79s)
Loading annotation RBIs from sorbet/rbi/annotations...  Done (1.04s)
Looking for duplicates...  Done (0.56s)

No duplicates found in shim RBIs

real	4m43.293s

Running tapioca check-shims after (using YARP):

Loading Sorbet payload...  Done (3.09s)
Loading shim RBIs from sorbet/rbi/shims... Done (2.28s)
Loading gem RBIs from sorbet/rbi/gems...  Done (18.49s)
Loading dsl RBIs from sorbet/rbi/dsl...  Done (21.41s)
Loading annotation RBIs from sorbet/rbi/annotations...  Done (0.51s)
Looking for duplicates...  Done (0.52s)

No duplicates found in shim RBIs

real	0m56.171s

@Morriar Morriar added enhancement New feature or request dependencies Pull requests that update a dependency file labels Sep 5, 2023
@Morriar Morriar requested a review from a team as a code owner September 5, 2023 19:27
@Morriar Morriar self-assigned this Sep 5, 2023
spec.add_dependency("sorbet-runtime", ">= 0.5.9204")
spec.add_dependency("unparser", ">= 0.5.6")
Copy link
Contributor

Choose a reason for hiding this comment

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

Since YARP releases may contain breaking changes while still under develpment, should be put an upper limit on this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This may help us find and fix these bugs faster

begin_line: yarp_location.start_line,
end_line: yarp_location.end_line,
begin_column: yarp_location.start_column,
end_column: yarp_location.end_column + 1, # TODO: Why is this off by one?
Copy link
Contributor

Choose a reason for hiding this comment

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

Known issue, I'm verifying Kevin's suggestion for a fix here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great! I'm going to merge and update this once fixed 👍

@Morriar
Copy link
Collaborator Author

Morriar commented Sep 6, 2023

I bumped YARP to 0.0.10 and tested the changes on core 👍

Base automatically changed from at-ruby27 to main September 6, 2023 15:56
@Morriar Morriar requested a review from andyw8 September 7, 2023 15:09
Copy link
Contributor

@andyw8 andyw8 left a comment

Choose a reason for hiding this comment

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

I haven't read through every line of the lib/rbi/parser.rb changes, but I'm trusting the tests are sufficiently covering it.

assert_equal("unexpected token $end", e.message)
assert_equal("test_parse_real_file_with_error.rbi:2:0-2:0", e.location.to_s)
assert_equal("Expected to be able to parse an expression. Expected `end` to close `class` statement.", e.message)
# assert_equal("test_parse_real_file_with_error.rbi:1:10-1:10", e.location.to_s)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be reinstated?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah good idea. I commented it until we figure the weird locations returned by YARP but I can keep the wrong location in the assert instead

Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]>
@Morriar Morriar merged commit f5f1c43 into main Sep 7, 2023
9 checks passed
@Morriar Morriar deleted the at-yarp branch September 7, 2023 15:42
@shopify-shipit shopify-shipit bot temporarily deployed to production September 7, 2023 15:47 Inactive
@Morriar Morriar added the breaking-change Change breaking retro-compatibility label Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change Change breaking retro-compatibility dependencies Pull requests that update a dependency file enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants