Skip to content

Include anytostring inside concatstrings#6335

Open
casperisfine wants to merge 1 commit into
ruby:masterfrom
Shopify:str-interpolation-perf-2
Open

Include anytostring inside concatstrings#6335
casperisfine wants to merge 1 commit into
ruby:masterfrom
Shopify:str-interpolation-perf-2

Conversation

@casperisfine

Copy link
Copy Markdown
Contributor

This show another 10-12% improvement.

But not sure wether I'm missing something as to why it was done like this in the first place.

@casperisfine

Copy link
Copy Markdown
Contributor Author

Ok, so as expected it's quite more complicated than that.

The issue is that objtostring works as follow:

  • Check for various fast paths, and if we match return the optimized result
  • Otherwise behave like a regular to_s call.

But nothing guarantees that to_s returned a string, so then anytostring is executed, and if what objtostring produced wasn't a string, it fallbacks to the any_to_s helper.

We can't do that in concatstrings because at that point we lost track of the object on which to_s was called.

So if we had to inline, it would be anytostring inside objtostring.

@tekknolagi

Copy link
Copy Markdown
Contributor

Have you thought more about putting anytostring inside objtostring?

@byroot

byroot commented Apr 10, 2026

Copy link
Copy Markdown
Member

Nope, perhaps something I should resume.

@tekknolagi

tekknolagi commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

https://shru.gg

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