Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

gzm0
Copy link
Contributor

@gzm0 gzm0 commented Aug 6, 2023

Since we potentially need to do a default target check on every method lookup, we memoize calculated default targets.

Note that this might generate more default bridges than actually necessary. However, since they will not be marked as reachable, they will not even be synthesized.

@gzm0
Copy link
Contributor Author

gzm0 commented Aug 6, 2023

Only the last commit is part of this PR.

@gzm0 gzm0 requested a review from sjrd August 6, 2023 17:48
@gzm0
Copy link
Contributor Author

gzm0 commented Aug 6, 2023

@sjrd what kind of benchmarking does this need? I suspect method lookup is quite performance sensitive?

- Fixes scala-js#2520 (make default bridge generation smarter)
- Avoids traversal order dependent behavior.

Since we potentially need to do a default target check on every method
lookup, we memoize calculated default targets.

Note that this might generate more default bridges than actually
necessary. However, since they will not be marked as reachable, they
will not even be synthesized.
case Some(superClass) => tryLookupInherited(superClass)
case None => None
publicMethodInfos.get(methodName) match {
case Some(m) if !m.isAbstract => Some(m)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This keeps the previous behavior w.r.t. abstract methods, but it seems this is a problem:
If we try to call a method on a class that is abstract, won't we replace the abstract method info with the missing method info? (similar thing with default methods, but its unclear to me ATM whether that can happen).

Copy link
Member

Choose a reason for hiding this comment

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

That seems to be the case, yes. But it also doesn't seem to be an issue? Unless perhaps it adds more errors: trying to later call that method will report a missing declaration (because the abstract method is now missing). Is that what you're concerned about?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might add more errors, yes. My main concern here is about determinism: It would not surprise me if the exact errors here depend on the call graph traversal order. But in any case, this is not something related to this PR.

@sjrd
Copy link
Member

sjrd commented Aug 6, 2023

@sjrd what kind of benchmarking does this need? I suspect method lookup is quite performance sensitive?

One effective thing to measure is successive relinkings of the test suite. Using forceRelinkForStabilityTest can do that without cleaning. Then use last testSuite2_12/Test/fastLinkJS to see the time taken by the analyzer.

Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

Looks good :)

@gzm0
Copy link
Contributor Author

gzm0 commented Aug 12, 2023

speed

No significant difference on 21 runs (1 batch run, 20 incremental runs). IMO good to merge. @sjrd WDYT?

@gzm0 gzm0 requested a review from sjrd August 12, 2023 10:48
Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

Nice 🙂

@sjrd sjrd merged commit 2da5417 into scala-js:main Aug 12, 2023
@gzm0 gzm0 deleted the better-default branch August 12, 2023 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make default bridge generation smarter
2 participants