Classify a star for the rows that list it, not every star each time the index is built

The search index and the route index gave every one of the 455 571 stars a subtitle up front
through spectralClassification, which filtered the dwarf table afresh on each call; the star
field's tints read the same table once per BP−RP star. Both indices now carry the star itself
and classify it only for the rows shown (entrySubtitle): eight search results, a few route
options. The two filtered columns of the table are built once.

Node, over the shipped catalogue, five runs: classifying every star 121-167 ms before, 56-62
after hoisting the table alone; reading the sequence at every BP−RP colour 187-216 ms, now
111-127. In the app on :4302, two cold loads each, the long task when the Search tab opens was
264-380 ms (median 280) before and 164-276 ms (median 171) after; the longest boot task 863 and
875 ms before, 654 and 741 after.

Tests: the search spec checks its index holds no classification and the row still reads
"Star · ~M8"; the scene spec now reads the route options, and checks its index holds none either.
Controls: classifying every star in the search index, doing so in the route index, and route
options printing the index's subtitle each fail the named test.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-29 23:30:53 +02:00
co-authored by Claude Opus 5.5
parent ff744a00de
commit 18faa6d0b2
6 changed files with 46 additions and 12 deletions
+9 -2
View File
@@ -158,6 +158,13 @@ const DWARF_SEQUENCE: readonly (readonly [string, number, number | null, number,
['M8.5', 2.16, 5.1, 2420, -5.78, -3.09]
];
/**
* The rows each colour is tabulated for, filtered once. Filtered on every call, the search index
* and the star field's tints, which read the table for each of the 455 571 stars, spent 140-230
* ms of the main thread on it at boot, and the search index again on each opening of its tab.
*/
const ROWS_WITH_COLOUR = { 1: DWARF_SEQUENCE.filter((row) => row[1] !== null), 2: DWARF_SEQUENCE.filter((row) => row[2] !== null) } as const;
/**
* The spectral type of the dwarf whose colour is nearest, for the stars no catalogue classified —
* every Gaia star, 83 % of the map. An estimate, and the caller must say so: it assumes a dwarf,
@@ -167,7 +174,7 @@ const DWARF_SEQUENCE: readonly (readonly [string, number, number | null, number,
*/
export function spectralTypeFromColor(colorIndex: number | null, system: 'B-V' | 'BP-RP' = 'B-V'): string | null {
const column = system === 'B-V' ? 1 : 2;
const rows = DWARF_SEQUENCE.filter((row) => row[column] !== null);
const rows = ROWS_WITH_COLOUR[column];
if (colorIndex === null || !(colorIndex >= rows[0][column]! && colorIndex <= rows[rows.length - 1][column]!)) {
return null;
}
@@ -213,7 +220,7 @@ export interface DwarfSequencePoint {
*/
export function dwarfSequenceAtColor(colorIndex: number | null, system: 'B-V' | 'BP-RP' = 'B-V', clampToTable = false): DwarfSequencePoint | null {
const column = system === 'B-V' ? 1 : 2;
const rows = DWARF_SEQUENCE.filter((row) => row[column] !== null);
const rows = ROWS_WITH_COLOUR[column];
const [bluest, reddest] = [rows[0][column]!, rows[rows.length - 1][column]!];
if (colorIndex === null || !Number.isFinite(colorIndex) || (!clampToTable && !(colorIndex >= bluest && colorIndex <= reddest))) {
return null;