Skip to content

Commit 605dc89

Browse files
committed
Optimize JSONStreamParser to improve performance by adjusting the frequency of yielding control during parsing based on time and count thresholds.
1 parent a2c8dda commit 605dc89

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

js/data/eurostat.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ class JSONStreamParser {
586586
let escape = false
587587
let token = ''
588588
let cnt = 0
589+
let t = Date.now()
589590

590591
const dqCode = '"'.charCodeAt(0)
591592
const bqCode = '\\'.charCodeAt(0)
@@ -643,9 +644,10 @@ class JSONStreamParser {
643644
break
644645
}
645646
}
646-
if (++cnt % 4096 === 0) {
647+
if (++cnt % 1024 === 0 || Date.now() - t > 100) {
647648
await new Promise(resolve => setTimeout(resolve, 0))
648649
cnt = 0
650+
t = Date.now()
649651
}
650652
}
651653
}

0 commit comments

Comments
 (0)