Skip to content

Commit

Permalink
Improve performance for really big JSON files
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Mar 8, 2019
1 parent b1f3930 commit 73298e8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions fx.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ module.exports = function start(filename, source) {
const expanded = new Set()
expanded.add('')

// Current filter code.
let currentCode = null

// Current search regexp and generator.
let highlight = null
let findGen = null
Expand Down Expand Up @@ -160,7 +163,13 @@ module.exports = function start(filename, source) {
})

input.on('update', function (code) {
update(code)
if (currentCode === code) {
return
}
currentCode = code
if (index.size < 10000) { // Don't live update in we have a big JSON file.
update(code)
}
complete(code)
})

Expand Down Expand Up @@ -409,7 +418,9 @@ module.exports = function start(filename, source) {

if (match) {
if (typeof json === 'object' && json.constructor === Object) {
const keys = Object.keys(json).filter(key => key.startsWith(match[1]))
const keys = Object.keys(json)
.filter(key => key.startsWith(match[1]))
.slice(0, 1000) // With lots of items, list takes forever to render.

// Hide if there is nothing to show or
// don't show if there is complete match.
Expand Down Expand Up @@ -616,4 +627,3 @@ function* dfs(v, path = '') {
}
}
}

0 comments on commit 73298e8

Please sign in to comment.