perf: add string flattening to reduce retained memory (node only)

add a memory footprint benchmark
This commit is contained in:
Patrick Malouin
2019-10-10 09:35:15 +08:00
committed by Jun Yang
parent 7bae5bcb79
commit 3ad512c51c
7 changed files with 102 additions and 6 deletions
+3
View File
@@ -0,0 +1,3 @@
export function flatten (str: string) {
return str
}
+10
View File
@@ -0,0 +1,10 @@
/**
* This function forces a string to be re-instantiated in memory using a flat representation instead of a graph
* of concatenated strings. This is an optimization to reduce the memory footprint of token string fragments after
* they are parsed.
* This optimization targets the V8 javascript engine and only works on Node.js.
* @param {string} str
*/
export function flatten (str: string) {
return Buffer.from(str).toString()
}