perf: remove transient strings to reduce memory

This commit is contained in:
harttle
2020-03-14 19:04:18 +08:00
committed by Jun Yang
parent 0f25017d5d
commit 3dfdf982c9
16 changed files with 124 additions and 125 deletions
+10 -6
View File
@@ -28,10 +28,12 @@ function html () {
for (let i = 0; i < SAMPLE_COUNT; i++) {
templates.push(engine.parse(str))
}
global.gc()
const diff1 = (getHeapStatistics().used_heap_size - base) / SAMPLE_COUNT
console.log(`${h(str.length)} lorem-html before GC x ${h(diff1)}/tpl (${SAMPLE_COUNT} instances sampled)`)
const diff = (getHeapStatistics().used_heap_size - base) / SAMPLE_COUNT
console.log(`${h(str.length)} HTML template x ${h(diff)}/instance (${SAMPLE_COUNT} instances sampled)`)
global.gc()
const diff2 = (getHeapStatistics().used_heap_size - base) / SAMPLE_COUNT
console.log(`${h(str.length)} lorem-html after GC x ${h(diff2)}/tpl (${SAMPLE_COUNT} instances sampled)`)
}
function todolist () {
@@ -44,10 +46,12 @@ function todolist () {
for (let i = 0; i < SAMPLE_COUNT; i++) {
templates.push(engine.parse(str))
}
global.gc()
const diff1 = (getHeapStatistics().used_heap_size - base) / SAMPLE_COUNT
console.log(`${h(str.length)} todolist before GC x ${h(diff1)}/tpl (${SAMPLE_COUNT} instances sampled)`)
const diff = (getHeapStatistics().used_heap_size - base) / SAMPLE_COUNT
console.log(`${h(str.length)} Todo template x ${h(diff)}/instance (${SAMPLE_COUNT} instances sampled)`)
global.gc()
const diff2 = (getHeapStatistics().used_heap_size - base) / SAMPLE_COUNT
console.log(`${h(str.length)} todolist after GC x ${h(diff2)}/tpl (${SAMPLE_COUNT} instances sampled)`)
}
function h (size) {