Skip to content

[Strings] string.encode #4776

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 5 commits into from
Jul 7, 2022
Merged

[Strings] string.encode #4776

merged 5 commits into from
Jul 7, 2022

Conversation

kripken
Copy link
Member

@kripken kripken commented Jul 7, 2022

No description provided.

@kripken kripken requested review from tlively and aheejin July 7, 2022 18:50
@@ -678,6 +678,9 @@ struct CostAnalyzer : public OverriddenVisitor<CostAnalyzer, CostType> {
CostType visitStringMeasure(StringMeasure* curr) {
return 6 + visit(curr->ref);
}
CostType visitStringEncode(StringEncode* curr) {
return 6 + visit(curr->ref) + visit(curr->ptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess cost for encoding should be bigger than visitArrayCopy has. Also it should depends on format. encode_wtf16 probably will have slightly less cost than encode_wtf8

Copy link
Member Author

Choose a reason for hiding this comment

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

True. I'm not sure how much it matters though, or how we can pick a better number here. "6" is just what we use for an operation that performs a loop, which we can't really predict. If we wanted to be really precise perhaps we should emit "cannot predict" here somehow. But in practice these numbers mainly matter when comparing equivalent code, and there isn't really equivalent code to StringEncode (that is, there is no other sequence that is identical to it, like say eqz(eqz(x)) == (x != 0)).

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it!

@kripken kripken merged commit 19a4375 into main Jul 7, 2022
@kripken kripken deleted the string.encode branch July 7, 2022 22:43
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