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

Load docstrings lazily from TASTy #20148

Closed
wants to merge 3 commits into from

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Apr 10, 2024

Now we are always able to load docstrings from TASTy, even if -Yread-docs is not set. The -Yread-docs flag loads the doc strings eagerly, as it did before.

Fixes #20106

Now we are always able to load docstings from TASTy, even if `-Yread-docs` is not set.
The `-Yread-docs` flag loads the doc strings eagerly, as it did before.

Fixes scala#20106
Reading it from the tree would be unreliable as doc might not have been
loaded yet. Doc stings should be accessed from the `ContextDocstrings`.
@nicolasstucki nicolasstucki marked this pull request as ready for review April 11, 2024 09:16
Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

When do we actually read comments? My concern is that creates a huge map in all cases now. We carefully engineered the Tasty unpickler to be fast and not create too much memory. Now we are throwing that out of the window for something as trivial as reading comments. I believe if we do that we have to first optimize comment handling as thoroughly as the rest of the representations. Right mow it is a completely different standard, nobody cared very much about efficiency, since we believed that in high-stress scenarios (clean build of a large code base) comments would not be read anyway.

Unrelated: I have a similar concern for unused warnings which do something relatively "easy" yet need a significant part of the compilation time, simply because they have not been optimized well.

Alternatives: Can we create/populate the map only once the first comment is read? Can we read the Tasty buffer twice to get comments? Or maybe have a more compact representation of where comments start, so that comments can be easily read on demand afterwards? Note that using a util.IntMap does not allocate any value objects. Maybe one could use that to get the comment start of a symbol.

@@ -31,7 +31,7 @@ class SnippetCompiler(
rootCtx.setSetting(rootCtx.settings.experimental, true)
rootCtx.setSetting(rootCtx.settings.YretainTrees, true)
rootCtx.setSetting(rootCtx.settings.YcookComments, true)
rootCtx.setSetting(rootCtx.settings.YreadComments, true)
rootCtx.setSetting(rootCtx.settings.YreadDocsEagerly, true)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is a usage scenario where I might want readDocsEargerly?

Copy link
Contributor Author

@nicolasstucki nicolasstucki Apr 16, 2024

Choose a reason for hiding this comment

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

None. I just kept to be able to benchmark the difference in performance.

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

I think lazy loading is nice, but then

  • it has to be so fast that we don't need to worry about performance
  • it should avoid all settings, including readDocsEagerly.

@SethTisue SethTisue changed the title Load docstings lazily from TASTy Load docstrings lazily from TASTy Apr 15, 2024
@nicolasstucki
Copy link
Contributor Author

We need to address the concerns and explore the alternatives described in #20148 (review)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Symbol.docString not available in tests
2 participants