Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve chokidar watcher analysis performances #2349

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP
  • Loading branch information
taratatach committed Oct 16, 2024
commit 12ad2b4644aae241eae7df0f04ba90cb9520401c
36 changes: 22 additions & 14 deletions core/local/chokidar/analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,26 @@ class LocalChangeMap {
if (change) return callback(change)
}

put(c /*: LocalChange */, updated /*: ?boolean */) {
if (updated) {
for (const [k, v] of this.changesByPath) {
if (v == c) {
this.changesByPath.delete(k)
break
}
put(c /*: LocalChange */, toReplace /*: ?LocalChange */) {
if (toReplace) {
this.changesByPath.delete(toReplace.path.normalize())
this.changesByPath.set(c.path.normalize(), c)

if (typeof toReplace.ino === 'number') {
this.changesByInode.set(toReplace.ino, c)
} else {
const index = this.changes.indexOf(toReplace)
this.changes.splice(index, 1, c)
}
} else {
this.changesByPath.set(c.path.normalize(), c)

if (typeof c.ino === 'number') {
this.changesByInode.set(c.ino, c)
} else {
this.changes.push(c)
}
}
this.changesByPath.set(c.path.normalize(), c)
if (typeof c.ino === 'number') this.changesByInode.set(c.ino, c)
else this.changes.push(c)
}

flush() /*: LocalChange[] */ {
Expand Down Expand Up @@ -176,9 +184,9 @@ function analyseEvents(
const result = analyseEvent(e, changesFound)
if (result == null) continue // No change was found. Skip event.

// A new change was found or updated
const [change, updated] = result
changesFound.put(change, updated)
// A new change was found or one that should be replaced
const [change, toReplace] = result
changesFound.put(change, toReplace)
} catch (err) {
const sentry = err.name === 'InvalidLocalMoveEvent'
log.error('Invalid local move event', { err, path: e.path, sentry })
Expand All @@ -196,7 +204,7 @@ function analyseEvents(
function analyseEvent(
e /*: LocalEvent */,
previousChanges /*: LocalChangeMap */
) /*: ?[LocalChange, boolean] */ {
) /*: ?[LocalChange, ?LocalChange] */ {
const sameInodeChange = previousChanges.findByInode(getInode(e))

switch (e.type) {
Expand Down
Loading
Loading