Efficiency of modernize stringsbuilder rewrites

32 views
Skip to first unread message

Tom Limoncelli

unread,
2:32 PM (5 hours ago) 2:32 PM
to golang-nuts
One of the coolest features of `modernize` is that it turns a series
of string appends into a strings.Builder + WriteString() statements.
This is more efficient because it avoids allocations.

However I notice that if the append is multiple strings (s += a + b)
the transform results in allocations:

- s += "foo" + myvariable
+ s.WriteString("foo" + myvariable)

Would it be more efficient to rewrite it as 2 statements:

+ s.WriteString("foo")
+ s.WriteString(myvariable)

Is this worth filing a feature request or is the potential improvement
negligible?

Tom

--
Blog: https://www.yesthatblog.com/
Reply all
Reply to author
Forward
0 new messages