gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmaind2e6d26bMerge branch 'records-park55' into mainTrackermain/lib/bootscan.hl

6.9 KB

  1. // lib/bootscan.hl — THE BOOT SCANS (tracker.worldapi.org#45, mission 043): ONE streamed pass per big table at start, feeding every
  2. // derived structure that needs that table, instead of one `find(null, null)` per module (each decoded the WHOLE table into one
  3. // 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
  4. // pauses those arrays caused — missions/388-trkmem-report.md in the Hybriel repo). `iterate(null, null)` hands the rows out one at a
  5. // time and frees each (but see eachRow: the plugin decodes the file into one native arena first).
  6. //
  7. // titles → catalog.hl (the public lists, genres) shows.hl (slug map) search.hl (title entries, TMDB / TVmaze ids, slugs)
  8. // shortids.hl (owners, queue) people.hl (cast photos)
  9. // episodes → catalog.hl (newest released / upcoming dates)
  10. // people → search.hl (person entries) shortids.hl people.hl (/people's order)
  11. //
  12. // Every module keeps its own lazy build (ensureIndex, ensureShortIds, …) built from the SAME per-record functions used here, so a
  13. // tool that imports one module still works; project.hl calls bootScan() once before the first request. The order inside a table is
  14. // the table's, as with the old per-module scans (search entries, short id ownership and the id queue come out the same).
  15. import { now } from 'hl:time'
  16. import { env, setEnv } from 'hl:proc'
  17. import { showsTable, episodesTable, personsTable, noteSlugsOf, markSlugIdsBuilt } from './shows.hl'
  18. import { beginIndex, noteIndexShow, noteIndexEpisode, finishIndexStep } from './catalog.hl'
  19. import { indexShow, noteIndexPerson, finishSearchIndex } from './search.hl'
  20. import { loadOldShortIds, noteShortIdRow, finishShortIds } from './shortids.hl'
  21. import { noteCastProfiles, markPeopleIndexesBuilt, noteViewRow, finishPeopleViewStep } from './people.hl'
  22. import { warm } from './warm.hl'
  23. // THE SCAN IS RESUMABLE (mission T17): `bootStep(budgetMs)` takes rows from the table's cursor until the budget is used up and
  24. // answers true once all three passes are done. project.hl runs it a few seconds before the server is made (a small database is
  25. // then complete at the first request, as always) and goes on from a clock after the server listens, so the first request does not
  26. // 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
  27. // is built show a "starting up" note (components/warm*.hl, the parent of those pages) instead of being built on half a map.
  28. // The rows, the per-row functions and the order are the ones of the former blocking passes: the structures come out the same.
  29. static scanned = { titles = 0 episodes = 0 people = 0 castPhotos = 0 ms = 0 }
  30. static job = { started = false done = false phase = '' cursor = null t0 = 0 tPhase = 0 paced = false closing = false peopleMarked = false }
  31. // 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
  32. // cast + crew) against a small live heap, so it ran 350 times for the titles alone; a higher pacing lets the garbage grow
  33. // to a few hundred MB first. Per pass, sized to what is live then; the operator's own HL_GC_PACING is never touched.
  34. static paceOf = [8, 3, 1, 1]
  35. static pace = (&step) => {
  36. if (job.paced) { setEnv('HL_GC_PACING', '' + paceOf[step]) }
  37. return true
  38. }
  39. static beginScan = (&t) => {
  40. job.started = true
  41. job.t0 = t
  42. job.tPhase = t
  43. job.paced = env('HL_GC_PACING') == null
  44. if (env('TRACKER_GC_PACE') != null) {
  45. let k = 0
  46. for (v of env('TRACKER_GC_PACE').split(',')) { paceOf[k] = toNumber(v) k = k + 1 }
  47. }
  48. warm.running = true
  49. warm.startedAt = t
  50. warm.phase = 'titles'
  51. beginIndex()
  52. loadOldShortIds()
  53. job.phase = 'titles'
  54. job.cursor = showsTable.cursor(null, null)
  55. pace(0)
  56. return true
  57. }
  58. static rowTitle = (&s) => {
  59. noteIndexShow(&s)
  60. noteSlugsOf(&s)
  61. indexShow(&s)
  62. noteShortIdRow('show', &s)
  63. scanned.castPhotos = scanned.castPhotos + noteCastProfiles(&s)
  64. scanned.titles = scanned.titles + 1
  65. return null
  66. }
  67. static rowEpisode = (&e) => {
  68. noteIndexEpisode(&e)
  69. scanned.episodes = scanned.episodes + 1
  70. return null
  71. }
  72. static rowPerson = (&p) => {
  73. noteIndexPerson(&p)
  74. noteShortIdRow('person', &p)
  75. noteViewRow(&p)
  76. scanned.people = scanned.people + 1
  77. return null
  78. }
  79. // a pass is out of rows: its closing work (the same calls, in the same order, as the blocking passes made), then the next pass
  80. static endPass = (Number budgetMs) => {
  81. if (job.phase == 'titles') {
  82. markSlugIdsBuilt()
  83. t = now()
  84. console.log('boot scan: ' + scanned.titles + ' titles in ' + (t - job.tPhase) + ' ms')
  85. warm.titles = true
  86. job.phase = 'episodes'
  87. warm.phase = 'episodes'
  88. job.tPhase = t
  89. // The catalog keeps only the owning title and release date; merged rows are skipped.
  90. job.cursor = episodesTable.cursor(null, null, ['show', 'mergedInto', 'release'])
  91. pace(1)
  92. } else if (job.phase == 'episodes') {
  93. if (!finishIndexStep(budgetMs)) { return false }
  94. t = now()
  95. console.log('boot scan: ' + scanned.episodes + ' episodes in ' + (t - job.tPhase) + ' ms')
  96. warm.catalog = true
  97. job.phase = 'people'
  98. warm.phase = 'people'
  99. job.tPhase = t
  100. job.cursor = personsTable.cursor(null, null)
  101. pace(2)
  102. } else {
  103. if (!job.peopleMarked) {
  104. markPeopleIndexesBuilt(&scanned.castPhotos)
  105. finishSearchIndex(&job.t0)
  106. finishShortIds(&job.t0)
  107. job.peopleMarked = true
  108. }
  109. if (!finishPeopleViewStep(budgetMs)) { return false }
  110. t = now()
  111. console.log('boot scan: ' + scanned.people + ' people in ' + (t - job.tPhase) + ' ms')
  112. // tracker#37's log line (tests/browser.mjs reads it)
  113. console.log('people view: ' + scanned.people + ' people, ' + scanned.castPhotos + ' cast photos in ' + (t - job.tPhase) + ' ms')
  114. scanned.ms = t - job.t0
  115. console.log('boot scan: done in ' + scanned.ms + ' ms')
  116. job.done = true
  117. job.cursor = null
  118. warm.people = true
  119. warm.running = false
  120. warm.phase = 'done'
  121. warm.readyAt = t
  122. pace(3)
  123. }
  124. job.closing = false
  125. return true
  126. }
  127. // the scan is under way from here on (warm.running), before the first row — project.hl calls it when the server will listen first
  128. static bootBegin = () => {
  129. if (!job.started) { beginScan(now()) }
  130. return true
  131. }
  132. // rows for up to `budgetMs` (the clock is read every 32 rows); true when the whole scan is done
  133. static bootStep = (&budgetMs) => {
  134. if (job.done) { return true }
  135. t = now()
  136. if (!job.started) { beginScan(&t) }
  137. let n = 0
  138. while (!job.done) {
  139. if (job.closing) {
  140. if (!endPass(budgetMs - (now() - t))) { return false }
  141. if (now() - t >= budgetMs) { return job.done }
  142. } else {
  143. r = job.cursor.next()
  144. if (r == null) { job.closing = true }
  145. else {
  146. if (job.phase == 'titles') { rowTitle(&r) } else if (job.phase == 'episodes') { rowEpisode(&r) } else { rowPerson(&r) }
  147. n = n + 1
  148. if (n % 32 == 0 && now() - t >= budgetMs) { return false }
  149. }
  150. }
  151. }
  152. return true
  153. }
  154. // the whole scan at once (tools, and the way every start worked before mission T17)
  155. static bootScan = () => {
  156. bootStep(2000000000)
  157. return scanned
  158. }

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