Skip to content

Improve Signature lookups, Make Signature immutable #2582

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

Merged
merged 12 commits into from
Dec 5, 2022

Conversation

jtenner
Copy link
Contributor

@jtenner jtenner commented Nov 30, 2022

In this pull request, the Signature class becomes immutable. The reason being is because signature type lookups have become a big bottleneck for libraries that have a lot of type signatures. We can uniquely identify these signatures by calculating their string representation using signature.toString(). This causes a lot of not so very straightforward problems within the compiler, the program, and the resolver. For instance, the compiler now has to call the newStub function with the maximum arguments, and when resolving a type in the resolver, we are not allowed to simply modify the return type of signatures, and instead we create a new one to obtain the proper function type id at instantiation time.

Changes involved:

  • compiler tests fixtures updated
  • Signatures are now immutable
  • Some changes involving signatureReference equality have changed



  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

…on being is because signature type lookups have become a big bottleneck for libraries that have a lot of type signatures. We can uniquely identify these signatures by calculating their string representation using signature.toString(). This causes a lot of not so very straightforward problems within the compiler, the program, and the resolver. For instance, the compiler now has to call the `newStub` function with the maximum arguments, and when resolving a type in the resolver, we are not allowed to simply modify the return type of signatures, and instead we create a new one to obtain the proper function type id at instantiation time.

Changes involved:
- compiler tests fixtures updated
- Signatures are now immutable
- Some changes involving signatureReference equality have changed
@jtenner
Copy link
Contributor Author

jtenner commented Nov 30, 2022

After some local testing, I got some really amazing speed increases. I tested nearly 250k function signatures in that list, and the time it took to deal with them reduced to thirty seconds instead of a whopping 25 minutes (or more.) This can be regarded as a generalized improvement.

Copy link
Member

@dcodeIO dcodeIO left a comment

Choose a reason for hiding this comment

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

Overall looks good to me, modulo comments :)

Copy link
Member

@CountBleck CountBleck left a comment

Choose a reason for hiding this comment

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

I didn't think of this, but .new isn't the best name for this. .create would be better.
Also, there is a stray output.txt file.

src/resolver.ts Outdated
let signature = new Signature(this.program, parameterTypes, returnType, thisType);
signature.requiredParameters = requiredParameters;
signature.hasRest = hasRest;
let signature = Signature.new(this.program, parameterTypes, returnType, thisType, requiredParameters, hasRest);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let signature = Signature.new(this.program, parameterTypes, returnType, thisType, requiredParameters, hasRest);
let signature = Signature.create(this.program, parameterTypes, returnType, thisType, requiredParameters, hasRest);

Copy link
Member

@dcodeIO dcodeIO left a comment

Choose a reason for hiding this comment

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

Looking good, thanks! :)

@dcodeIO dcodeIO merged commit 378659a into AssemblyScript:main Dec 5, 2022
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.

3 participants