You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This was even briefly mentioned by @mdempsky in 2016, but as far as I can see it was never followed up on: #17725 (comment)
Another potential route would be for string(bs[0]) and string(bs[:1]) to not allocate thanks to the compiler, as it can statically know that len==1. However, that could be built on top of the runtime optimization, as a form of skipping the len check and calling the non-allocating runtime func directly.
If there is interest in investigating the performance penalty of such a change, I can work on a prototype CL to get some measurements. Unless this was already measured and discarded by someone, and I haven't been able to find a thread for it.
Go ahead. This is small enough I don't think we need the proposal process for it.
randall77
changed the title
Proposal: runtime: don't allocate when converting a single byte to string
runtime: don't allocate when converting a single byte to string
Feb 28, 2018
I had a change sitting around in my tree from Sat Mar 4 16:55:03 2017 to do this. Apparently I had decided at the time that it wasn't worth it? Unclear. Anyway, I mailed it. The perf numbers may be stale.
And to echo Keith, for small- to medium-sized optimization ideas, no proposal needed in general.
For example:
At the moment, all three allocate, easily measured with:
There is some precedent to this, I believe. For example:
This was even briefly mentioned by @mdempsky in 2016, but as far as I can see it was never followed up on: #17725 (comment)
Another potential route would be for
string(bs[0])
andstring(bs[:1])
to not allocate thanks to the compiler, as it can statically know that len==1. However, that could be built on top of the runtime optimization, as a form of skipping the len check and calling the non-allocating runtime func directly.If there is interest in investigating the performance penalty of such a change, I can work on a prototype CL to get some measurements. Unless this was already measured and discarded by someone, and I haven't been able to find a thread for it.
/cc @randall77 @josharian
The text was updated successfully, but these errors were encountered: