Skip to content

[NFC] Make public type collection more efficient #7561

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 2 commits into from
Apr 29, 2025
Merged

Conversation

tlively
Copy link
Member

@tlively tlively commented Apr 29, 2025

Previously public type collection worked by collecting all types in the
module, classifying their visibility, then picking out all the public
types to return. However, visibility classification requires directly
finding the public types from the imports and exports in the first
place, so the initial step of collecting all the types was unnecessary.

Refactor the code so getPublicHeapTypes calculates the public types
directly from the imports and exports and classifyTypes uses those
results to classify visibility only when collecting all types from the
module anyway.

Previously public type collection worked by collecting all types in the
module, classifying their visibility, then picking out all the public
types to return. However, visibility classification requires directly
finding the public types from the imports and exports in the first
place, so the initial step of collecting all the types was unnecessary.

Refactor the code so `getPublicHeapTypes` calculates the public types
directly from the imports and exports and `classifyTypes` uses those
results to classify visibility only when collecting all types from the
module anyway.
@tlively tlively requested a review from kripken April 29, 2025 19:42
}
}

void setIndices(IndexedHeapTypes& indexedTypes) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Heh, the moved code was so large that it's a smaller diff to show everything else moving around it.

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

Nice!

return types;
}

std::vector<HeapType> getPublicHeapTypes(Module& wasm) {
// We will need to traverse the types used by public types and mark them
// public as well.
Copy link
Member

Choose a reason for hiding this comment

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

"as well" seems odd in the first comment of a function?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's referring to the original public types also introduced in this sentence, so I think it makes sense. I will clarify in general, though.

@tlively tlively merged commit 3b0ab2c into main Apr 29, 2025
14 checks passed
@tlively tlively deleted the efficient-public-types branch April 29, 2025 20:28
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.

2 participants