perf(escapeAllSwigTags): reducing GC overhead#5620
Conversation
How to testgit clone -b perf/mem https://github.com/D-Sketon/hexo.git
cd hexo
npm install
npm test |
Pull Request Test Coverage Report for Build 13679073585Details
💛 - Coveralls |
SukkaW
left a comment
There was a problem hiding this comment.
I believe that the root cause of the issue is that string concatenation doesn't copy strings; instead, it points to the existing strings using pointers. This is good for performance, so we should retain this behavior.
On the other hand, the concatenated string holds the reference of the old string, preventing the old string from being released.
Instead of manually creating a StringBuilder, you can try replacing return output with return output.replace('#'.repeat(output.length + 1), '') to see if it reduces GC pressure.
See also: https://romgrk.com/posts/optimizing-javascript#8-use-strings-carefully
|
I might have figured out why there's a memory difference. Although Assuming each post has 5,000 characters and there are 4,000 posts, On the other hand, using |
|
@SukkaW Using |







What does it do?
A large amount of string concatenation can result in numerous consString objects, which cannot be cleared during Scavenge. This leads to old generation expansion.
12x many-posts


before PR
after PR
12x many-posts concurrency=20


before PR
after PR
4x many-posts concurrency=20

before PR
after PR

1x many-posts concurrency=20


before PR
after PR
Screenshots
Pull request tasks