tracker
All repositories: gitoria
6.9 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, finishIndexStep } from './catalog.hl'import { indexShow, noteIndexPerson, finishSearchIndex } from './search.hl'import { loadOldShortIds, noteShortIdRow, finishShortIds } from './shortids.hl'import { noteCastProfiles, markPeopleIndexesBuilt, noteViewRow, finishPeopleViewStep } 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 closing = false peopleMarked = 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 = (Number budgetMs) => {if (job.phase == 'titles') {markSlugIdsBuilt()t = now()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') {if (!finishIndexStep(budgetMs)) { return false }t = now()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 {if (!job.peopleMarked) {markPeopleIndexesBuilt(&scanned.castPhotos)finishSearchIndex(&job.t0)finishShortIds(&job.t0)job.peopleMarked = true}if (!finishPeopleViewStep(budgetMs)) { return false }t = now()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)}job.closing = falsereturn 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) {if (job.closing) {if (!endPass(budgetMs - (now() - t))) { return false }if (now() - t >= budgetMs) { return job.done }} else {r = job.cursor.next()if (r == null) { job.closing = true }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
- d2e6d26bMerge branch 'records-park55' into mainTracker
- f567f025|||PR records: park #55, no Claude workers ruleTracker
- c21aff6bMerge branch 'records-hm55c' into mainTracker
- 9ba258d3|||PR records: HM55b resultTracker
- 64f2d300Merge branch 'records-hm55b2' into mainTracker
- ae3b80dc|||PR records: HM55b briefTracker
- 7ef3cb3bMerge branch 'records-st55' into mainTracker
- fec2e080|||PR records: STATUS HM55Tracker
- 8e174918Merge branch 'records-hm55b' into mainTracker
- b1ecee57|||PR records: HM55 stateTracker
- 28eab08cMerge branch 'records-hm55' into mainTracker
- d3edaa05|||PR records: HM55 start, PROCEDURES.mdTracker
- 3059f86cMerge branch 'records-design-rule' into mainTracker
- 421a4809|||PR records: his-design rule (Apollo 2026-11-13)Tracker
- d1390692Merge branch 'records-dp75b' into mainTracker
- a4d1a7d2|||PR records: later steps checked, branch auditTracker
- e070e16fMerge branch 'records-dp75' into mainTracker
- 642b4fa8|||PR records: DP75 day62 live, AP62 briefTracker
- bfc4ea4dMerge branch 'ap62' into mainTracker
- 2c95ac46|||PR AP62: re-vendor Hybriel set day62 (source 70341ad2, bin a54f5f08)Tracker