minotor 12.0.0 → 12.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -9
- package/dist/cli/perf.d.ts +15 -5
- package/dist/cli.mjs +129 -117
- package/dist/cli.mjs.map +1 -1
- package/dist/parser.cjs.js +37 -19
- package/dist/parser.cjs.js.map +1 -1
- package/dist/parser.esm.js +37 -19
- package/dist/parser.esm.js.map +1 -1
- package/dist/router.cjs.js +1 -1
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.esm.js +1 -1
- package/dist/router.esm.js.map +1 -1
- package/dist/router.umd.js +1 -1
- package/dist/router.umd.js.map +1 -1
- package/dist/routing/state.d.ts +2 -2
- package/dist/stops/stopsIndex.d.ts +1 -1
- package/dist/timetable/route.d.ts +2 -0
- package/package.json +2 -2
- package/src/cli/minotor.ts +19 -2
- package/src/cli/perf.ts +94 -107
- package/src/routing/__tests__/state.test.ts +29 -0
- package/src/routing/state.ts +11 -3
- package/src/stops/__tests__/stopFinder.test.ts +13 -0
- package/src/stops/stopsIndex.ts +13 -19
- package/src/timetable/__tests__/io.test.ts +27 -0
- package/src/timetable/__tests__/route.test.ts +30 -0
- package/src/timetable/io.ts +15 -1
- package/src/timetable/route.ts +19 -5
- package/src/timetable/timetable.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
## [12.0.1](https://github.com/aubryio/minotor/compare/v12.0.0...v12.0.1) (2026-10-24)
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
###
|
|
4
|
+
### Performance Improvements
|
|
5
5
|
|
|
6
|
-
*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
### BREAKING CHANGES
|
|
10
|
-
|
|
11
|
-
* Route types, pick-up and drop-off types and transfer types are now numerical rather
|
|
12
|
-
than strings in the API.
|
|
6
|
+
* memory quick wins (reduce retained buffers, array allocations, etc.) ([#80](https://github.com/aubryio/minotor/issues/80)) ([d8371f6](https://github.com/aubryio/minotor/commit/d8371f6150b328c00cc9466e057bebf5cac0a8a0))
|
package/dist/cli/perf.d.ts
CHANGED
|
@@ -2,7 +2,17 @@ import { Query, RangeQuery, Router, StopsIndex } from '../router.js';
|
|
|
2
2
|
type PerformanceResult = {
|
|
3
3
|
label: string;
|
|
4
4
|
meanTimeUs: number;
|
|
5
|
-
|
|
5
|
+
meanHeapMiB: number;
|
|
6
|
+
meanArrayBuffersMiB: number;
|
|
7
|
+
};
|
|
8
|
+
/** Observed deltas, not peak memory or total allocations; GC can make them negative. */
|
|
9
|
+
export declare const measurePerformance: (operation: () => unknown, iterations: number) => Omit<PerformanceResult, "label">;
|
|
10
|
+
/** Measure retained storage after collection, keeping only the returned value alive. */
|
|
11
|
+
export declare const measureRetainedMemory: <T>(operation: () => T) => {
|
|
12
|
+
value: T;
|
|
13
|
+
loadTimeMs: number;
|
|
14
|
+
retainedHeapMiB?: number;
|
|
15
|
+
retainedArrayBuffersMiB?: number;
|
|
6
16
|
};
|
|
7
17
|
/**
|
|
8
18
|
* Loads a list of routing queries from a JSON file and resolves the
|
|
@@ -46,7 +56,7 @@ export declare const loadRangeQueriesFromJson: (filePath: string, stopsIndex: St
|
|
|
46
56
|
* yield a more stable mean at the cost of longer wall-clock time.
|
|
47
57
|
* @param stopsIndex - Used to resolve stop names for result labels.
|
|
48
58
|
* @returns An array of {@link PerformanceResult} objects, one per query, each
|
|
49
|
-
* containing the mean wall-clock time (µs) and mean heap
|
|
59
|
+
* containing the mean wall-clock time (µs) and mean heap and ArrayBuffer deltas (MiB).
|
|
50
60
|
*/
|
|
51
61
|
export declare const testRouterPerformance: (router: Router, tasks: Query[], iterations: number, stopsIndex: StopsIndex) => PerformanceResult[];
|
|
52
62
|
/**
|
|
@@ -60,7 +70,7 @@ export declare const testRouterPerformance: (router: Router, tasks: Query[], ite
|
|
|
60
70
|
* @param iterations - Number of times `bestRoute` is called per query.
|
|
61
71
|
* @param stopsIndex - Used to resolve stop names for result labels.
|
|
62
72
|
* @returns An array of {@link PerformanceResult} objects, one per query, each
|
|
63
|
-
* containing the mean wall-clock time (µs) and mean heap
|
|
73
|
+
* containing the mean wall-clock time (µs) and mean heap and ArrayBuffer deltas (MiB) for the
|
|
64
74
|
* `bestRoute` call alone.
|
|
65
75
|
*/
|
|
66
76
|
export declare const testBestRoutePerformance: (router: Router, tasks: Query[], iterations: number, stopsIndex: StopsIndex) => PerformanceResult[];
|
|
@@ -73,7 +83,7 @@ export declare const testBestRoutePerformance: (router: Router, tasks: Query[],
|
|
|
73
83
|
* @param iterations - Number of times each query is repeated.
|
|
74
84
|
* @param stopsIndex - Used to resolve stop names for result labels.
|
|
75
85
|
* @returns An array of {@link PerformanceResult} objects, one per query, each
|
|
76
|
-
* containing the mean wall-clock time (µs) and mean heap
|
|
86
|
+
* containing the mean wall-clock time (µs) and mean heap and ArrayBuffer deltas (MiB).
|
|
77
87
|
*/
|
|
78
88
|
export declare const testRangeRouterPerformance: (router: Router, tasks: RangeQuery[], iterations: number, stopsIndex: StopsIndex) => PerformanceResult[];
|
|
79
89
|
/**
|
|
@@ -87,7 +97,7 @@ export declare const testRangeRouterPerformance: (router: Router, tasks: RangeQu
|
|
|
87
97
|
* @param iterations - Number of times `getRoutes` is called per query.
|
|
88
98
|
* @param stopsIndex - Used to resolve stop names for result labels.
|
|
89
99
|
* @returns An array of {@link PerformanceResult} objects, one per query, each
|
|
90
|
-
* containing the mean wall-clock time (µs) and mean heap
|
|
100
|
+
* containing the mean wall-clock time (µs) and mean heap and ArrayBuffer deltas (MiB) for the
|
|
91
101
|
* `getRoutes` call alone.
|
|
92
102
|
*/
|
|
93
103
|
export declare const testRangeResultPerformance: (router: Router, tasks: RangeQuery[], iterations: number, stopsIndex: StopsIndex) => PerformanceResult[];
|
package/dist/cli.mjs
CHANGED
|
@@ -16281,7 +16281,7 @@ class StopsIndex {
|
|
|
16281
16281
|
this.stops = stops;
|
|
16282
16282
|
this.sourceStopsMap = new Map();
|
|
16283
16283
|
const stopsSet = new Map();
|
|
16284
|
-
this.
|
|
16284
|
+
this.geoStopIds = [];
|
|
16285
16285
|
for (let id = 0; id < stops.length; id++) {
|
|
16286
16286
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
16287
16287
|
const stop = stops[id];
|
|
@@ -16297,11 +16297,7 @@ class StopsIndex {
|
|
|
16297
16297
|
});
|
|
16298
16298
|
}
|
|
16299
16299
|
if (stop.lat && stop.lon) {
|
|
16300
|
-
this.
|
|
16301
|
-
id: id,
|
|
16302
|
-
lat: stop.lat,
|
|
16303
|
-
lon: stop.lon,
|
|
16304
|
-
});
|
|
16300
|
+
this.geoStopIds.push(id);
|
|
16305
16301
|
}
|
|
16306
16302
|
}
|
|
16307
16303
|
this.textIndex = H({
|
|
@@ -16312,11 +16308,12 @@ class StopsIndex {
|
|
|
16312
16308
|
});
|
|
16313
16309
|
const stopsArray = Array.from(stopsSet.values());
|
|
16314
16310
|
S(this.textIndex, stopsArray);
|
|
16315
|
-
this.geoIndex = new KDBush(this.
|
|
16316
|
-
for (let i = 0; i < this.
|
|
16311
|
+
this.geoIndex = new KDBush(this.geoStopIds.length);
|
|
16312
|
+
for (let i = 0; i < this.geoStopIds.length; i++) {
|
|
16317
16313
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
16318
|
-
const
|
|
16319
|
-
|
|
16314
|
+
const stop = this.stops[this.geoStopIds[i]];
|
|
16315
|
+
// Coordinates were checked when collecting geoStopIds.
|
|
16316
|
+
this.geoIndex.add(stop.lon, stop.lat);
|
|
16320
16317
|
}
|
|
16321
16318
|
this.geoIndex.finish();
|
|
16322
16319
|
}
|
|
@@ -16358,8 +16355,9 @@ class StopsIndex {
|
|
|
16358
16355
|
* @returns An array of Stop objects that match the search query.
|
|
16359
16356
|
*/
|
|
16360
16357
|
findStopsByName(query, maxResults = 5) {
|
|
16361
|
-
|
|
16362
|
-
|
|
16358
|
+
return R(this.textIndex, query)
|
|
16359
|
+
.slice(0, maxResults)
|
|
16360
|
+
.map((result) => this.stops[result.id]);
|
|
16363
16361
|
}
|
|
16364
16362
|
/**
|
|
16365
16363
|
* Finds stops by their geographic location using latitude and longitude.
|
|
@@ -16372,8 +16370,8 @@ class StopsIndex {
|
|
|
16372
16370
|
*/
|
|
16373
16371
|
findStopsByLocation(lat, lon, maxResults = 5, radius = 0.5) {
|
|
16374
16372
|
const nearestStops = around(this.geoIndex, lon, lat, maxResults, radius).map((id) => {
|
|
16375
|
-
const
|
|
16376
|
-
return this.stops[
|
|
16373
|
+
const stopId = this.geoStopIds[id];
|
|
16374
|
+
return this.stops[stopId];
|
|
16377
16375
|
});
|
|
16378
16376
|
return nearestStops;
|
|
16379
16377
|
}
|
|
@@ -17473,11 +17471,14 @@ let Route$1 = class Route {
|
|
|
17473
17471
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
17474
17472
|
const stopId = stops[i];
|
|
17475
17473
|
const existingIndices = this.stopIndices.get(stopId);
|
|
17476
|
-
if (existingIndices) {
|
|
17477
|
-
|
|
17474
|
+
if (existingIndices === undefined) {
|
|
17475
|
+
this.stopIndices.set(stopId, i);
|
|
17476
|
+
}
|
|
17477
|
+
else if (typeof existingIndices === 'number') {
|
|
17478
|
+
this.stopIndices.set(stopId, [existingIndices, i]);
|
|
17478
17479
|
}
|
|
17479
17480
|
else {
|
|
17480
|
-
|
|
17481
|
+
existingIndices.push(i);
|
|
17481
17482
|
}
|
|
17482
17483
|
}
|
|
17483
17484
|
}
|
|
@@ -17758,8 +17759,19 @@ let Route$1 = class Route {
|
|
|
17758
17759
|
if (stopIndex === undefined) {
|
|
17759
17760
|
return [];
|
|
17760
17761
|
}
|
|
17762
|
+
if (typeof stopIndex === 'number') {
|
|
17763
|
+
// Preserve stable, mutable array results for callers that request all indices.
|
|
17764
|
+
const indices = [stopIndex];
|
|
17765
|
+
this.stopIndices.set(stopId, indices);
|
|
17766
|
+
return indices;
|
|
17767
|
+
}
|
|
17761
17768
|
return stopIndex;
|
|
17762
17769
|
}
|
|
17770
|
+
/** Returns the first occurrence without allocating an array. */
|
|
17771
|
+
firstStopRouteIndex(stopId) {
|
|
17772
|
+
const indices = this.stopIndices.get(stopId);
|
|
17773
|
+
return typeof indices === 'number' ? indices : indices === null || indices === void 0 ? void 0 : indices[0];
|
|
17774
|
+
}
|
|
17763
17775
|
/**
|
|
17764
17776
|
* Retrieves the id of a stop at a given index in a route.
|
|
17765
17777
|
* @param stopRouteIndex The route index of the stop.
|
|
@@ -17944,11 +17956,17 @@ const deserializeStopsAdjacency = (protoStopsAdjacency) => {
|
|
|
17944
17956
|
};
|
|
17945
17957
|
const deserializeRoutesAdjacency = (protoRoutesAdjacency) => {
|
|
17946
17958
|
const routesAdjacency = [];
|
|
17959
|
+
// Own the compact payload so small protobuf views do not retain the input file.
|
|
17960
|
+
const pickupDropOffStorage = new Uint8Array(protoRoutesAdjacency.reduce((size, route) => size + route.pickupDropOffTypes.byteLength, 0));
|
|
17961
|
+
let pickupOffset = 0;
|
|
17947
17962
|
for (let i = 0; i < protoRoutesAdjacency.length; i++) {
|
|
17948
17963
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
17949
17964
|
const value = protoRoutesAdjacency[i];
|
|
17950
17965
|
const stops = bytesToUint32Array(value.stops);
|
|
17951
|
-
|
|
17966
|
+
pickupDropOffStorage.set(value.pickupDropOffTypes, pickupOffset);
|
|
17967
|
+
const pickupDropOffTypes = pickupDropOffStorage.subarray(pickupOffset, pickupOffset + value.pickupDropOffTypes.byteLength);
|
|
17968
|
+
pickupOffset += value.pickupDropOffTypes.byteLength;
|
|
17969
|
+
routesAdjacency.push(new Route$1(i, bytesToUint16Array(value.stopTimes), pickupDropOffTypes, stops, value.serviceRouteId));
|
|
17952
17970
|
}
|
|
17953
17971
|
return routesAdjacency;
|
|
17954
17972
|
};
|
|
@@ -18270,7 +18288,7 @@ class Timetable {
|
|
|
18270
18288
|
if (!serviceRoute || !transportModes.has(serviceRoute.type))
|
|
18271
18289
|
continue;
|
|
18272
18290
|
}
|
|
18273
|
-
const originStopIndex = route.
|
|
18291
|
+
const originStopIndex = route.firstStopRouteIndex(originStop);
|
|
18274
18292
|
const existingHopOnStopIndex = reachableRoutes.get(route);
|
|
18275
18293
|
if (existingHopOnStopIndex !== undefined) {
|
|
18276
18294
|
if (originStopIndex < existingHopOnStopIndex) {
|
|
@@ -23083,8 +23101,8 @@ class RoutingState {
|
|
|
23083
23101
|
*/
|
|
23084
23102
|
this.maxArrivalTime = UNREACHED_TIME;
|
|
23085
23103
|
/**
|
|
23086
|
-
* Every stop
|
|
23087
|
-
*
|
|
23104
|
+
* Every stop reached during the current run, recorded once in first-reached
|
|
23105
|
+
* order. Used by {@link resetFor} to clear
|
|
23088
23106
|
* only the touched entries instead of scanning the entire array.
|
|
23089
23107
|
*/
|
|
23090
23108
|
this.reachedStops = [];
|
|
@@ -23176,7 +23194,9 @@ class RoutingState {
|
|
|
23176
23194
|
* @param leg The round number (number of transit legs taken so far).
|
|
23177
23195
|
*/
|
|
23178
23196
|
updateArrival(stop, time, leg) {
|
|
23179
|
-
this.
|
|
23197
|
+
if (this.earliestArrivalTimes[stop] === UNREACHED_TIME) {
|
|
23198
|
+
this.reachedStops.push(stop);
|
|
23199
|
+
}
|
|
23180
23200
|
this.earliestArrivalTimes[stop] = time;
|
|
23181
23201
|
this.earliestArrivalLegs[stop] = leg;
|
|
23182
23202
|
if (this.destinationSet.has(stop) && time < this._destinationBest) {
|
|
@@ -23314,6 +23334,13 @@ class RoutingState {
|
|
|
23314
23334
|
return arr;
|
|
23315
23335
|
});
|
|
23316
23336
|
state.graph.splice(0, state.graph.length, ...denseRounds);
|
|
23337
|
+
state.reachedStops.length = 0;
|
|
23338
|
+
const touched = new Set(arrivals.map(([stop]) => stop));
|
|
23339
|
+
for (const round of graph) {
|
|
23340
|
+
for (const [stop] of round)
|
|
23341
|
+
touched.add(stop);
|
|
23342
|
+
}
|
|
23343
|
+
state.reachedStops.push(...touched);
|
|
23317
23344
|
return state;
|
|
23318
23345
|
}
|
|
23319
23346
|
}
|
|
@@ -24090,6 +24117,50 @@ class Router {
|
|
|
24090
24117
|
}
|
|
24091
24118
|
}
|
|
24092
24119
|
|
|
24120
|
+
/** Observed deltas, not peak memory or total allocations; GC can make them negative. */
|
|
24121
|
+
const measurePerformance = (operation, iterations) => {
|
|
24122
|
+
var _a;
|
|
24123
|
+
let totalTime = 0;
|
|
24124
|
+
let totalHeap = 0;
|
|
24125
|
+
let totalArrayBuffers = 0;
|
|
24126
|
+
for (let i = 0; i < iterations; i++) {
|
|
24127
|
+
(_a = global.gc) === null || _a === void 0 ? void 0 : _a.call(global);
|
|
24128
|
+
const before = process.memoryUsage();
|
|
24129
|
+
const start = performance$1.now();
|
|
24130
|
+
operation();
|
|
24131
|
+
const end = performance$1.now();
|
|
24132
|
+
const after = process.memoryUsage();
|
|
24133
|
+
totalTime += (end - start) * 1000;
|
|
24134
|
+
totalHeap += after.heapUsed - before.heapUsed;
|
|
24135
|
+
totalArrayBuffers += after.arrayBuffers - before.arrayBuffers;
|
|
24136
|
+
}
|
|
24137
|
+
return {
|
|
24138
|
+
meanTimeUs: totalTime / iterations,
|
|
24139
|
+
meanHeapMiB: totalHeap / iterations / (1024 * 1024),
|
|
24140
|
+
meanArrayBuffersMiB: totalArrayBuffers / iterations / (1024 * 1024),
|
|
24141
|
+
};
|
|
24142
|
+
};
|
|
24143
|
+
/** Measure retained storage after collection, keeping only the returned value alive. */
|
|
24144
|
+
const measureRetainedMemory = (operation) => {
|
|
24145
|
+
const gc = global.gc;
|
|
24146
|
+
gc === null || gc === void 0 ? void 0 : gc();
|
|
24147
|
+
const before = gc ? process.memoryUsage() : undefined;
|
|
24148
|
+
const start = performance$1.now();
|
|
24149
|
+
const value = operation();
|
|
24150
|
+
const loadTimeMs = performance$1.now() - start;
|
|
24151
|
+
if (!gc || !before)
|
|
24152
|
+
return { value, loadTimeMs };
|
|
24153
|
+
// A second collection lets backing storage released by finalization settle.
|
|
24154
|
+
gc();
|
|
24155
|
+
gc();
|
|
24156
|
+
const after = process.memoryUsage();
|
|
24157
|
+
return {
|
|
24158
|
+
value,
|
|
24159
|
+
loadTimeMs,
|
|
24160
|
+
retainedHeapMiB: (after.heapUsed - before.heapUsed) / (1024 * 1024),
|
|
24161
|
+
retainedArrayBuffersMiB: (after.arrayBuffers - before.arrayBuffers) / (1024 * 1024),
|
|
24162
|
+
};
|
|
24163
|
+
};
|
|
24093
24164
|
const renderTable = (columns, rows, footerRow) => {
|
|
24094
24165
|
const bar = (l, m, r) => l + columns.map((c) => '─'.repeat(c.width + 2)).join(m) + r;
|
|
24095
24166
|
const renderRow = (cells) => '│' +
|
|
@@ -24217,32 +24288,12 @@ const loadRangeQueriesFromJson = (filePath, stopsIndex) => {
|
|
|
24217
24288
|
* yield a more stable mean at the cost of longer wall-clock time.
|
|
24218
24289
|
* @param stopsIndex - Used to resolve stop names for result labels.
|
|
24219
24290
|
* @returns An array of {@link PerformanceResult} objects, one per query, each
|
|
24220
|
-
* containing the mean wall-clock time (µs) and mean heap
|
|
24291
|
+
* containing the mean wall-clock time (µs) and mean heap and ArrayBuffer deltas (MiB).
|
|
24221
24292
|
*/
|
|
24222
24293
|
const testRouterPerformance = (router, tasks, iterations, stopsIndex) => {
|
|
24223
24294
|
const results = [];
|
|
24224
24295
|
for (const task of tasks) {
|
|
24225
|
-
|
|
24226
|
-
let totalMemory = 0;
|
|
24227
|
-
for (let i = 0; i < iterations; i++) {
|
|
24228
|
-
if (global.gc) {
|
|
24229
|
-
global.gc();
|
|
24230
|
-
}
|
|
24231
|
-
const startMemory = process.memoryUsage().heapUsed;
|
|
24232
|
-
const startTime = performance$1.now();
|
|
24233
|
-
router.route(task);
|
|
24234
|
-
const endTime = performance$1.now();
|
|
24235
|
-
const endMemory = process.memoryUsage().heapUsed;
|
|
24236
|
-
totalTime += (endTime - startTime) * 1000;
|
|
24237
|
-
if (endMemory >= startMemory) {
|
|
24238
|
-
totalMemory += endMemory - startMemory;
|
|
24239
|
-
}
|
|
24240
|
-
}
|
|
24241
|
-
results.push({
|
|
24242
|
-
label: buildQueryLabel(task, stopsIndex),
|
|
24243
|
-
meanTimeUs: totalTime / iterations,
|
|
24244
|
-
meanMemoryMb: totalMemory / iterations / (1024 * 1024),
|
|
24245
|
-
});
|
|
24296
|
+
results.push(Object.assign({ label: buildQueryLabel(task, stopsIndex) }, measurePerformance(() => router.route(task), iterations)));
|
|
24246
24297
|
}
|
|
24247
24298
|
return results;
|
|
24248
24299
|
};
|
|
@@ -24257,34 +24308,14 @@ const testRouterPerformance = (router, tasks, iterations, stopsIndex) => {
|
|
|
24257
24308
|
* @param iterations - Number of times `bestRoute` is called per query.
|
|
24258
24309
|
* @param stopsIndex - Used to resolve stop names for result labels.
|
|
24259
24310
|
* @returns An array of {@link PerformanceResult} objects, one per query, each
|
|
24260
|
-
* containing the mean wall-clock time (µs) and mean heap
|
|
24311
|
+
* containing the mean wall-clock time (µs) and mean heap and ArrayBuffer deltas (MiB) for the
|
|
24261
24312
|
* `bestRoute` call alone.
|
|
24262
24313
|
*/
|
|
24263
24314
|
const testBestRoutePerformance = (router, tasks, iterations, stopsIndex) => {
|
|
24264
24315
|
const results = [];
|
|
24265
24316
|
for (const task of tasks) {
|
|
24266
24317
|
const result = router.route(task);
|
|
24267
|
-
|
|
24268
|
-
let totalMemory = 0;
|
|
24269
|
-
for (let i = 0; i < iterations; i++) {
|
|
24270
|
-
if (global.gc) {
|
|
24271
|
-
global.gc();
|
|
24272
|
-
}
|
|
24273
|
-
const startMemory = process.memoryUsage().heapUsed;
|
|
24274
|
-
const startTime = performance$1.now();
|
|
24275
|
-
result.bestRoute();
|
|
24276
|
-
const endTime = performance$1.now();
|
|
24277
|
-
const endMemory = process.memoryUsage().heapUsed;
|
|
24278
|
-
totalTime += (endTime - startTime) * 1000;
|
|
24279
|
-
if (endMemory >= startMemory) {
|
|
24280
|
-
totalMemory += endMemory - startMemory;
|
|
24281
|
-
}
|
|
24282
|
-
}
|
|
24283
|
-
results.push({
|
|
24284
|
-
label: buildQueryLabel(task, stopsIndex),
|
|
24285
|
-
meanTimeUs: totalTime / iterations,
|
|
24286
|
-
meanMemoryMb: totalMemory / iterations / (1024 * 1024),
|
|
24287
|
-
});
|
|
24318
|
+
results.push(Object.assign({ label: buildQueryLabel(task, stopsIndex) }, measurePerformance(() => result.bestRoute(), iterations)));
|
|
24288
24319
|
}
|
|
24289
24320
|
return results;
|
|
24290
24321
|
};
|
|
@@ -24297,32 +24328,12 @@ const testBestRoutePerformance = (router, tasks, iterations, stopsIndex) => {
|
|
|
24297
24328
|
* @param iterations - Number of times each query is repeated.
|
|
24298
24329
|
* @param stopsIndex - Used to resolve stop names for result labels.
|
|
24299
24330
|
* @returns An array of {@link PerformanceResult} objects, one per query, each
|
|
24300
|
-
* containing the mean wall-clock time (µs) and mean heap
|
|
24331
|
+
* containing the mean wall-clock time (µs) and mean heap and ArrayBuffer deltas (MiB).
|
|
24301
24332
|
*/
|
|
24302
24333
|
const testRangeRouterPerformance = (router, tasks, iterations, stopsIndex) => {
|
|
24303
24334
|
const results = [];
|
|
24304
24335
|
for (const task of tasks) {
|
|
24305
|
-
|
|
24306
|
-
let totalMemory = 0;
|
|
24307
|
-
for (let i = 0; i < iterations; i++) {
|
|
24308
|
-
if (global.gc) {
|
|
24309
|
-
global.gc();
|
|
24310
|
-
}
|
|
24311
|
-
const startMemory = process.memoryUsage().heapUsed;
|
|
24312
|
-
const startTime = performance$1.now();
|
|
24313
|
-
router.rangeRoute(task);
|
|
24314
|
-
const endTime = performance$1.now();
|
|
24315
|
-
const endMemory = process.memoryUsage().heapUsed;
|
|
24316
|
-
totalTime += (endTime - startTime) * 1000;
|
|
24317
|
-
if (endMemory >= startMemory) {
|
|
24318
|
-
totalMemory += endMemory - startMemory;
|
|
24319
|
-
}
|
|
24320
|
-
}
|
|
24321
|
-
results.push({
|
|
24322
|
-
label: buildQueryLabel(task, stopsIndex),
|
|
24323
|
-
meanTimeUs: totalTime / iterations,
|
|
24324
|
-
meanMemoryMb: totalMemory / iterations / (1024 * 1024),
|
|
24325
|
-
});
|
|
24336
|
+
results.push(Object.assign({ label: buildQueryLabel(task, stopsIndex) }, measurePerformance(() => router.rangeRoute(task), iterations)));
|
|
24326
24337
|
}
|
|
24327
24338
|
return results;
|
|
24328
24339
|
};
|
|
@@ -24337,38 +24348,17 @@ const testRangeRouterPerformance = (router, tasks, iterations, stopsIndex) => {
|
|
|
24337
24348
|
* @param iterations - Number of times `getRoutes` is called per query.
|
|
24338
24349
|
* @param stopsIndex - Used to resolve stop names for result labels.
|
|
24339
24350
|
* @returns An array of {@link PerformanceResult} objects, one per query, each
|
|
24340
|
-
* containing the mean wall-clock time (µs) and mean heap
|
|
24351
|
+
* containing the mean wall-clock time (µs) and mean heap and ArrayBuffer deltas (MiB) for the
|
|
24341
24352
|
* `getRoutes` call alone.
|
|
24342
24353
|
*/
|
|
24343
24354
|
const testRangeResultPerformance = (router, tasks, iterations, stopsIndex) => {
|
|
24344
24355
|
const results = [];
|
|
24345
24356
|
for (const task of tasks) {
|
|
24346
24357
|
const rangeResult = router.rangeRoute(task);
|
|
24347
|
-
|
|
24348
|
-
let totalMemory = 0;
|
|
24349
|
-
for (let i = 0; i < iterations; i++) {
|
|
24350
|
-
if (global.gc) {
|
|
24351
|
-
global.gc();
|
|
24352
|
-
}
|
|
24353
|
-
const startMemory = process.memoryUsage().heapUsed;
|
|
24354
|
-
const startTime = performance$1.now();
|
|
24355
|
-
rangeResult.getRoutes();
|
|
24356
|
-
const endTime = performance$1.now();
|
|
24357
|
-
const endMemory = process.memoryUsage().heapUsed;
|
|
24358
|
-
totalTime += (endTime - startTime) * 1000;
|
|
24359
|
-
if (endMemory >= startMemory) {
|
|
24360
|
-
totalMemory += endMemory - startMemory;
|
|
24361
|
-
}
|
|
24362
|
-
}
|
|
24363
|
-
results.push({
|
|
24364
|
-
label: buildQueryLabel(task, stopsIndex),
|
|
24365
|
-
meanTimeUs: totalTime / iterations,
|
|
24366
|
-
meanMemoryMb: totalMemory / iterations / (1024 * 1024),
|
|
24367
|
-
});
|
|
24358
|
+
results.push(Object.assign({ label: buildQueryLabel(task, stopsIndex) }, measurePerformance(() => rangeResult.getRoutes(), iterations)));
|
|
24368
24359
|
}
|
|
24369
24360
|
return results;
|
|
24370
24361
|
};
|
|
24371
|
-
// ─── Output ───────────────────────────────────────────────────────────────────
|
|
24372
24362
|
/**
|
|
24373
24363
|
* Prints a table summary of performance results to stdout.
|
|
24374
24364
|
*
|
|
@@ -24388,12 +24378,16 @@ const prettyPrintPerformanceResults = (results, label = 'Performance Results') =
|
|
|
24388
24378
|
const fmtTime = (n) => Math.round(n).toLocaleString('en-US');
|
|
24389
24379
|
const fmtMem = (n) => n.toFixed(2);
|
|
24390
24380
|
const meanTime = results.reduce((s, r) => s + r.meanTimeUs, 0) / results.length;
|
|
24391
|
-
const meanMem = results.reduce((s, r) => s + r.
|
|
24381
|
+
const meanMem = results.reduce((s, r) => s + r.meanHeapMiB, 0) / results.length;
|
|
24382
|
+
const meanBuffers = results.reduce((s, r) => s + r.meanArrayBuffersMiB, 0) / results.length;
|
|
24392
24383
|
const queryHeader = 'Query';
|
|
24393
24384
|
const timeHeader = 'Time (µs)';
|
|
24394
|
-
const memHeader = '
|
|
24385
|
+
const memHeader = 'Heap Δ (MiB)';
|
|
24386
|
+
const buffersHeader = 'ArrayBuffers Δ (MiB)';
|
|
24395
24387
|
const timeVals = results.map((r) => fmtTime(r.meanTimeUs));
|
|
24396
|
-
const memVals = results.map((r) => fmtMem(r.
|
|
24388
|
+
const memVals = results.map((r) => fmtMem(r.meanHeapMiB));
|
|
24389
|
+
const bufferVals = results.map((r) => fmtMem(r.meanArrayBuffersMiB));
|
|
24390
|
+
const meanBuffersStr = fmtMem(meanBuffers);
|
|
24397
24391
|
const meanTimeStr = fmtTime(meanTime);
|
|
24398
24392
|
const meanMemStr = fmtMem(meanMem);
|
|
24399
24393
|
const queryWidth = Math.max(queryHeader.length, 'mean'.length, ...results.map((r) => r.label.length));
|
|
@@ -24403,17 +24397,26 @@ const prettyPrintPerformanceResults = (results, label = 'Performance Results') =
|
|
|
24403
24397
|
{ header: queryHeader, width: queryWidth, align: 'left' },
|
|
24404
24398
|
{ header: timeHeader, width: timeWidth, align: 'right' },
|
|
24405
24399
|
{ header: memHeader, width: memWidth, align: 'right' },
|
|
24400
|
+
{
|
|
24401
|
+
header: buffersHeader,
|
|
24402
|
+
width: Math.max(buffersHeader.length, meanBuffersStr.length, ...bufferVals.map((v) => v.length)),
|
|
24403
|
+
align: 'right',
|
|
24404
|
+
},
|
|
24406
24405
|
];
|
|
24407
24406
|
const rows = results.map((r, i) => {
|
|
24408
|
-
var _a, _b;
|
|
24407
|
+
var _a, _b, _c;
|
|
24409
24408
|
return [
|
|
24410
24409
|
r.label,
|
|
24411
24410
|
(_a = timeVals[i]) !== null && _a !== void 0 ? _a : '',
|
|
24412
24411
|
(_b = memVals[i]) !== null && _b !== void 0 ? _b : '',
|
|
24412
|
+
(_c = bufferVals[i]) !== null && _c !== void 0 ? _c : '',
|
|
24413
24413
|
];
|
|
24414
24414
|
});
|
|
24415
|
-
const footer = ['mean', meanTimeStr, meanMemStr];
|
|
24415
|
+
const footer = ['mean', meanTimeStr, meanMemStr, meanBuffersStr];
|
|
24416
24416
|
console.log(renderTable(columns, rows, footer));
|
|
24417
|
+
if (!global.gc) {
|
|
24418
|
+
console.log('Explicit GC unavailable; use node --expose-gc for more consistent samples.');
|
|
24419
|
+
}
|
|
24417
24420
|
};
|
|
24418
24421
|
|
|
24419
24422
|
/**
|
|
@@ -24954,7 +24957,16 @@ program
|
|
|
24954
24957
|
.option('-i, --iterations <number>', 'Number of iterations for performance tests', '20')
|
|
24955
24958
|
.action((routesPath, options) => {
|
|
24956
24959
|
const stopsIndex = StopsIndex.fromData(fs$1.readFileSync(options.stopsPath));
|
|
24957
|
-
const
|
|
24960
|
+
const loading = measureRetainedMemory(() => Timetable.fromData(fs$1.readFileSync(options.timetablePath)));
|
|
24961
|
+
const timetable = loading.value;
|
|
24962
|
+
console.log(`Timetable load (read + decode): ${loading.loadTimeMs.toFixed(2)} ms`);
|
|
24963
|
+
if (loading.retainedHeapMiB !== undefined &&
|
|
24964
|
+
loading.retainedArrayBuffersMiB !== undefined) {
|
|
24965
|
+
console.log(`Timetable retained after GC: heap ${loading.retainedHeapMiB.toFixed(2)} MiB; ArrayBuffers ${loading.retainedArrayBuffersMiB.toFixed(2)} MiB`);
|
|
24966
|
+
}
|
|
24967
|
+
else {
|
|
24968
|
+
console.log('Retained memory skipped: explicit GC unavailable; use node --expose-gc.');
|
|
24969
|
+
}
|
|
24958
24970
|
const router = new Router(timetable, stopsIndex);
|
|
24959
24971
|
const queries = loadQueriesFromJson(routesPath, stopsIndex);
|
|
24960
24972
|
const iterations = parseInt(options.iterations, 10);
|