-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
Use strings.Builder
to save some memory
#649
Labels
proposal
Proposal to add a new feature to pterm
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently, the
Srender
andSprint
method of some components uses "+=" to add the result. The string returned bySrender
would be very long, and using "+=" will waste some memory.strings.Builder
is specially designed to handle such scenarios.strings.Builder
was introduced in Go 1.10, and its doc says "A Builder is used to efficiently build a string".I did a simple benchmark using Barchart as an example:
and this is the result:
Using
strings.Builder
can save 28% of memory and reduce 4% allocations. There is no obvious change in the speed ofSrender
(in fact, the speed can become faster after reducing the number of memory allocations)The changes of code is also quite simple:
Code that needs to be modified:
Srender
andSprint
methods that require a lot of string concatenation. All modifications can be seen in the related PR submitted later.These modifications will not change the existing APIs. It is a simple and harmless refactoring.
I hope you would take the time to review this proposal.
The text was updated successfully, but these errors were encountered: