tracker
All repositories: gitoria
6.5 KB
// lib/bootscan.hl — THE BOOT SCANS (tracker.worldapi.org#45, mission 043): ONE streamed pass per big table at start, feeding every// derived structure that needs that table, instead of one `find(null, null)` per module (each decoded the WHOLE table into one// array: persons 621 K rows 11 s and 5.6 GB, episodes 1.4 M rows 9 s and +3 GB, five times over; 54 % of the boot was the GC// pauses those arrays caused — missions/388-trkmem-report.md in the Hybriel repo). `iterate(null, null)` hands the rows out one at a// time and frees each (but see eachRow: the plugin decodes the file into one native arena first).//// titles → catalog.hl (the public lists, genres) shows.hl (slug map) search.hl (title entries, TMDB / TVmaze ids, slugs)// shortids.hl (owners, queue) people.hl (cast photos)// episodes → catalog.hl (newest released / upcoming dates)// people → search.hl (person entries) shortids.hl people.hl (/people's order)//// Every module keeps its own lazy build (ensureIndex, ensureShortIds, …) built from the SAME per-record functions used here, so a// tool that imports one module still works; project.hl calls bootScan() once before the first request. The order inside a table is// the table's, as with the old per-module scans (search entries, short id ownership and the id queue come out the same).import { now } from 'hl:time'import { env, setEnv } from 'hl:proc'import { showsTable, episodesTable, personsTable, noteSlugsOf, markSlugIdsBuilt } from './shows.hl'import { beginIndex, noteIndexShow, noteIndexEpisode, finishIndex } from './catalog.hl'import { indexShow, noteIndexPerson, finishSearchIndex } from './search.hl'import { loadOldShortIds, noteShortIdRow, finishShortIds } from './shortids.hl'import { noteCastProfiles, markPeopleIndexesBuilt, noteViewRow, finishPeopleView } from './people.hl'import { warm } from './warm.hl'// THE SCAN IS RESUMABLE (mission T17): `bootStep(budgetMs)` takes rows from the table's cursor until the budget is used up and// answers true once all three passes are done. project.hl runs it a few seconds before the server is made (a small database is// then complete at the first request, as always) and goes on from a clock after the server listens, so the first request does not// wait for the full scan of 2.3 M rows. lib/warm.hl says how far it is (titles → catalog → all); the pages that need more than// is built show a "starting up" note (components/warm*.hl, the parent of those pages) instead of being built on half a map.// The rows, the per-row functions and the order are the ones of the former blocking passes: the structures come out the same.static scanned = { titles = 0 episodes = 0 people = 0 castPhotos = 0 ms = 0 }static job = { started = false done = false phase = '' cursor = null t0 = 0 tPhase = 0 paced = false }// Hybriel's collector waits for as much new garbage as the live heap held (HL_GC_PACING 1). The passes allocate fat rows (a title's// cast + crew) against a small live heap, so it ran 350 times for the titles alone; a higher pacing lets the garbage grow// to a few hundred MB first. Per pass, sized to what is live then; the operator's own HL_GC_PACING is never touched.static paceOf = [8, 3, 1, 1]static pace = (&step) => {if (job.paced) { setEnv('HL_GC_PACING', '' + paceOf[step]) }return true}static beginScan = (&t) => {job.started = truejob.t0 = tjob.tPhase = tjob.paced = env('HL_GC_PACING') == nullif (env('TRACKER_GC_PACE') != null) {let k = 0for (v of env('TRACKER_GC_PACE').split(',')) { paceOf[k] = toNumber(v) k = k + 1 }}warm.running = truewarm.startedAt = twarm.phase = 'titles'beginIndex()loadOldShortIds()job.phase = 'titles'job.cursor = showsTable.cursor(null, null)pace(0)return true}static rowTitle = (&s) => {noteIndexShow(&s)noteSlugsOf(&s)indexShow(&s)noteShortIdRow('show', &s)scanned.castPhotos = scanned.castPhotos + noteCastProfiles(&s)scanned.titles = scanned.titles + 1return null}static rowEpisode = (&e) => {noteIndexEpisode(&e)scanned.episodes = scanned.episodes + 1return null}static rowPerson = (&p) => {noteIndexPerson(&p)noteShortIdRow('person', &p)noteViewRow(&p)scanned.people = scanned.people + 1return null}// a pass is out of rows: its closing work (the same calls, in the same order, as the blocking passes made), then the next passstatic endPass = () => {t = now()if (job.phase == 'titles') {markSlugIdsBuilt()console.log('boot scan: ' + scanned.titles + ' titles in ' + (t - job.tPhase) + ' ms')warm.titles = truejob.phase = 'episodes'warm.phase = 'episodes'job.tPhase = t// The catalog keeps only the owning title and release date; merged rows are skipped.job.cursor = episodesTable.cursor(null, null, ['show', 'mergedInto', 'release'])pace(1)} else if (job.phase == 'episodes') {finishIndex()console.log('boot scan: ' + scanned.episodes + ' episodes in ' + (t - job.tPhase) + ' ms')warm.catalog = truejob.phase = 'people'warm.phase = 'people'job.tPhase = tjob.cursor = personsTable.cursor(null, null)pace(2)} else {markPeopleIndexesBuilt(&scanned.castPhotos)finishSearchIndex(&job.t0)finishShortIds(&job.t0)finishPeopleView()console.log('boot scan: ' + scanned.people + ' people in ' + (t - job.tPhase) + ' ms')// tracker#37's log line (tests/browser.mjs reads it)console.log('people view: ' + scanned.people + ' people, ' + scanned.castPhotos + ' cast photos in ' + (t - job.tPhase) + ' ms')scanned.ms = t - job.t0console.log('boot scan: done in ' + scanned.ms + ' ms')job.done = truejob.cursor = nullwarm.people = truewarm.running = falsewarm.phase = 'done'warm.readyAt = tpace(3)}return true}// the scan is under way from here on (warm.running), before the first row — project.hl calls it when the server will listen firststatic bootBegin = () => {if (!job.started) { beginScan(now()) }return true}// rows for up to `budgetMs` (the clock is read every 32 rows); true when the whole scan is donestatic bootStep = (&budgetMs) => {if (job.done) { return true }t = now()if (!job.started) { beginScan(&t) }let n = 0while (!job.done) {r = job.cursor.next()if (r == null) { endPass() }else {if (job.phase == 'titles') { rowTitle(&r) } else if (job.phase == 'episodes') { rowEpisode(&r) } else { rowPerson(&r) }n = n + 1if (n % 32 == 0 && now() - t >= budgetMs) { return false }}}return true}// the whole scan at once (tools, and the way every start worked before mission T17)static bootScan = () => {bootStep(2000000000)return scanned}
Branches
Latest commits
- a429d088Mission FF1mre
- 03bbfba3Log: AP56c causemre
- 24845fe3Log: AP56b result, AP56cmre
- 6a6d71eaLog: gitoria membershipmre
- 8b842dc8Log + CONDUCTOR: gitoria PR switch-onmre
- 6bb7c20estatus: window 2026-11-09mre
- 5db84974Log: Apollo window GO, AP56b started, BS1 copy removedmre
- e84586a7Mission AP56bmre
- 15917f03Record PR workflow rule (gitoria#50)mre
- 942ac995status: paused workers statemre
- 44b934e5log: respawn cleanupmre
- 03a80097Log: Anton GC A/Bmre
- c7cdef62Log: Apollo STOP, workers pausedmre
- d0c083fbLog: usage stopmre
- c6d464e5Log: Apollo GO backlog, AP56 and BS1 startedmre
- 1eb6f1a1Missions AP56, BS1mre
- 4871f8adLog: AP52 live on day52, browser gate greenmre
- d9bf2988Merge ap52: day52, tracker#58 server argument, #51 modal close rule, #56 keyed season rowsmre
- c4a60ef2Log: RT52 retest passed, AP52 startedmre
- 83760a55Browser gate: search results belong to the address form of the typed text (tracker#52 navigate replace)mre