Skip to content

Commit

Permalink
feat: Add Parcel watcher perf measures
Browse files Browse the repository at this point in the history
  • Loading branch information
taratatach committed Oct 24, 2024
1 parent 06c4fe6 commit 53b798c
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 4 deletions.
5 changes: 5 additions & 0 deletions core/local/channel_watcher/add_checksum.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const _ = require('lodash')
const path = require('path')

const { logger } = require('../../utils/logger')
const { measureTime } = require('../../utils/perfs')

const STEP_NAME = 'addChecksum'

Expand Down Expand Up @@ -56,6 +57,8 @@ function loop(
const syncPath = opts.config.syncPath

return channel.asyncMap(async events => {
const stopMeasure = measureTime('LocalWatcher#addChecksumStep')

for (const event of events) {
try {
if (event.incomplete) {
Expand All @@ -74,6 +77,8 @@ function loop(
log.debug('Cannot compute checksum', { err, event })
}
}

stopMeasure()
return events
}, opts.fatal)
}
Expand Down
5 changes: 5 additions & 0 deletions core/local/channel_watcher/add_infos.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const path = require('path')

const { kind } = require('../../metadata')
const { logger } = require('../../utils/logger')
const { measureTime } = require('../../utils/perfs')
const stater = require('../stater')

const STEP_NAME = 'addInfos'
Expand Down Expand Up @@ -47,6 +48,8 @@ function loop(
const syncPath = opts.config.syncPath

return channel.asyncMap(async events => {
const stopMeasure = measureTime('LocalWatcher#addInfosStep')

const batch = []
for (const event of events) {
if (event.kind === 'symlink') {
Expand Down Expand Up @@ -94,6 +97,8 @@ function loop(
}
batch.push(event)
}

stopMeasure()
return batch
}, opts.fatal)
}
Expand Down
13 changes: 9 additions & 4 deletions core/local/channel_watcher/await_write_finish.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const _ = require('lodash')

const Channel = require('./channel')
const { logger } = require('../../utils/logger')
const { measureTime } = require('../../utils/perfs')

const STEP_NAME = 'awaitWriteFinish'

Expand Down Expand Up @@ -245,17 +246,21 @@ async function awaitWriteFinish(channel /*: Channel */, out /*: Channel */) {

// eslint-disable-next-line no-constant-condition
while (true) {
const events = aggregateBatch(await channel.pop())
let nbCandidates = countFileWriteEvents(events)
debounce(waiting, events)
const events = await channel.pop()
const stopMeasure = measureTime('LocalWatcher#awaitWriteFinishStep')

const aggregatedEvents = aggregateBatch(events)
let nbCandidates = countFileWriteEvents(aggregatedEvents)
debounce(waiting, aggregatedEvents)

// Push the new batch of events in the queue
const timeout = setTimeout(() => {
out.push(waiting.shift().events)
sendReadyBatches(waiting, out)
}, DELAY)
waiting.push({ events, nbCandidates, timeout })
waiting.push({ events: aggregatedEvents, nbCandidates, timeout })

stopMeasure()
// Look if some batches can be sent without waiting
sendReadyBatches(waiting, out)
}
Expand Down
4 changes: 4 additions & 0 deletions core/local/channel_watcher/dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const _ = require('lodash')
const { buildDir, buildFile } = require('../../metadata')
const { WINDOWS_DATE_MIGRATION_FLAG } = require('../../config')
const { logger } = require('../../utils/logger')
const { measureTime } = require('../../utils/perfs')

const STEP_NAME = 'dispatch'
const component = `ChannelWatcher/${STEP_NAME}`
Expand Down Expand Up @@ -79,6 +80,8 @@ function loop(

function step(opts /*: DispatchOptions */) {
return async (batch /*: ChannelBatch */) => {
const stopMeasure = measureTime('LocalWatcher#dispatchStep')

const { [STEP_NAME]: dispatchState } = opts.state

clearTimeout(dispatchState.localEndTimeout)
Expand All @@ -96,6 +99,7 @@ function step(opts /*: DispatchOptions */) {
opts.events.emit('local-end')
}, LOCAL_END_NOTIFICATION_DELAY)

stopMeasure()
return batch
}
}
Expand Down
4 changes: 4 additions & 0 deletions core/local/channel_watcher/filter_ignored.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
const _ = require('lodash')

const { logger } = require('../../utils/logger')
const { measureTime } = require('../../utils/perfs')

/*::
import type Channel from './channel'
Expand Down Expand Up @@ -41,6 +42,8 @@ function loop(
})

return channel.map(events => {
const stopMeasure = measureTime('LocalWatcher#filterIgnoredStep')

const batch = []

for (const event of events) {
Expand All @@ -53,6 +56,7 @@ function loop(
}
}

stopMeasure()
return batch
}, opts.fatal)
}
Expand Down
4 changes: 4 additions & 0 deletions core/local/channel_watcher/incomplete_fixer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const path = require('path')

const stater = require('../stater')
const { logger } = require('../../utils/logger')
const { measureTime } = require('../../utils/perfs')

const STEP_NAME = 'incompleteFixer'

Expand Down Expand Up @@ -209,6 +210,8 @@ function step(
opts /*: IncompleteFixerOptions */
) {
return async (events /*: ChannelBatch */) /*: Promise<ChannelBatch> */ => {
const stopMeasure = measureTime('LocalWatcher#incompleteFixerStep')

const batch = new Set()

// Filter incomplete events
Expand Down Expand Up @@ -320,6 +323,7 @@ function step(
state.incompletes.push(...incompletes)
}

stopMeasure()
return Array.from(batch)
}
}
Expand Down
8 changes: 8 additions & 0 deletions core/local/channel_watcher/initial_diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const path = require('path')
const { WINDOWS_DATE_MIGRATION_FLAG } = require('../../config')
const { kind } = require('../../metadata')
const { logger } = require('../../utils/logger')
const { measureTime } = require('../../utils/perfs')
const Channel = require('./channel')

/*::
Expand Down Expand Up @@ -82,6 +83,8 @@ function loop(
async function initialState(
opts /*: { pouch: Pouch } */
) /*: Promise<InitialDiffState> */ {
const stopMeasure = measureTime('LocalWatcher#initialDiffInitialState')

const waiting /*: WaitingItem[] */ = []
const renamedEvents /*: ChannelEvent[] */ = []
const scannedPaths /*: Set<string> */ = new Set()
Expand All @@ -98,6 +101,7 @@ async function initialState(
}
}

stopMeasure()
return {
[STEP_NAME]: {
waiting,
Expand Down Expand Up @@ -152,6 +156,8 @@ async function initialDiff(
continue
}

const stopMeasure = measureTime('LocalWatcher#initialDiffStep')

let nbCandidates = 0

debounce(waiting, events)
Expand Down Expand Up @@ -247,6 +253,8 @@ async function initialDiff(
clearState(state)
}
batch.push(event)

stopMeasure()
}

// Push the new batch of events in the queue
Expand Down
4 changes: 4 additions & 0 deletions core/local/channel_watcher/overwrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const _ = require('lodash')

const Channel = require('./channel')
const { logger } = require('../../utils/logger')
const { measureTime } = require('../../utils/perfs')

/*::
import type { ChannelEvent, ChannelBatch } from './event'
Expand Down Expand Up @@ -161,13 +162,16 @@ const _loop = async (channel, out, opts) => {
// eslint-disable-next-line no-constant-condition
while (true) {
const events = await channel.pop()
const stopMeasure = measureTime('LocalWatcher#overwriteStep')

const {
state: { [STEP_NAME]: state }
} = opts

await step(events, opts)

rotateState(state, events, output)
stopMeasure()
}
}

Expand Down
4 changes: 4 additions & 0 deletions core/local/channel_watcher/parcel_producer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const parcel = require('@parcel/watcher')
const Channel = require('./channel')
const { INITIAL_SCAN_DONE } = require('./event')
const { logger } = require('../../utils/logger')
const { measureTime } = require('../../utils/perfs')

/*::
import type { Config } from '../../config'
Expand Down Expand Up @@ -120,10 +121,13 @@ class Producer {
}

async scan(relPath /*: string */) {
const stopParcelScanMeasure = measureTime('Parcel#scan')
const scanEvents = await parcel.scan(
path.join(this.config.syncPath, relPath),
{ backend }
)
stopParcelScanMeasure()

await this.processEvents(scanEvents, { fromScan: true })
}

Expand Down
5 changes: 5 additions & 0 deletions core/local/channel_watcher/scan_folder.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/

const { logger } = require('../../utils/logger')
const { measureTime } = require('../../utils/perfs')

const STEP_NAME = 'scanFolder'

Expand All @@ -31,6 +32,8 @@ function loop(
opts /*: { scan: Scanner, fatal: Error => any } */
) /*: Channel */ {
return channel.asyncMap(async batch => {
const stopMeasure = measureTime('LocalWatcher#scanFolderStep')

for (const event of batch) {
if (event.incomplete) {
continue
Expand All @@ -41,6 +44,8 @@ function loop(
})
}
}

stopMeasure()
return batch
}, opts.fatal)
}
5 changes: 5 additions & 0 deletions core/local/channel_watcher/win_identical_renaming.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const _ = require('lodash')
const Channel = require('./channel')
const { logger } = require('../../utils/logger')
const metadata = require('../../metadata')
const { measureTime } = require('../../utils/perfs')

/*::
import type { ChannelEvent, ChannelBatch } from './event'
Expand Down Expand Up @@ -144,6 +145,8 @@ const _loop = async (channel, out, opts) => {
// eslint-disable-next-line no-constant-condition
while (true) {
const events = await channel.pop()
const stopMeasure = measureTime('LocalWatcher#winIdenticalRenamingStep')

const {
state: { [STEP_NAME]: state }
} = opts
Expand All @@ -163,6 +166,8 @@ const _loop = async (channel, out, opts) => {
pending.timeout = setTimeout(() => {
output(pending)
}, DELAY)

stopMeasure()
}
}

Expand Down

0 comments on commit 53b798c

Please sign in to comment.