minotor 11.5.2 → 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 -3
- package/README.md +1 -1
- package/dist/cli/perf.d.ts +15 -5
- package/dist/cli.mjs +139 -151
- 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.d.ts +6 -5
- 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/route.d.ts +6 -9
- package/dist/routing/state.d.ts +2 -2
- package/dist/stops/stopsIndex.d.ts +1 -1
- package/dist/timetable/route.d.ts +7 -4
- package/package.json +2 -2
- package/src/__e2e__/router.test.ts +55 -56
- package/src/cli/minotor.ts +19 -2
- package/src/cli/perf.ts +94 -107
- package/src/cli/repl.ts +9 -5
- package/src/router.ts +21 -8
- package/src/routing/__tests__/plainRouter.test.ts +2 -2
- package/src/routing/__tests__/result.test.ts +1 -1
- package/src/routing/__tests__/route.test.ts +8 -7
- package/src/routing/__tests__/router.test.ts +21 -1
- package/src/routing/__tests__/state.test.ts +29 -0
- package/src/routing/result.ts +11 -45
- package/src/routing/route.ts +11 -13
- 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 +40 -12
- package/src/timetable/timetable.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +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
|
-
*
|
|
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/README.md
CHANGED
|
@@ -136,7 +136,7 @@ Query options:
|
|
|
136
136
|
| `minTransferTime` | `2 min` | Fallback minimum transfer time |
|
|
137
137
|
| `maxDuration` | unlimited | Maximum total journey duration from the query departure time |
|
|
138
138
|
| `maxInitialWaitingTime` | unlimited | Maximum wait for the first vehicle after arriving at the boarding stop |
|
|
139
|
-
| `transportModes` | all | Restrict to a subset of
|
|
139
|
+
| `transportModes` | all | Restrict to a subset of `RouteTypes` values |
|
|
140
140
|
|
|
141
141
|
#### Range query (browser or Node.js)
|
|
142
142
|
|
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) {
|
|
@@ -22642,13 +22660,13 @@ class Route {
|
|
|
22642
22660
|
const fromStop = `From: ${leg.from.name}${leg.from.platform ? ` (Pl. ${leg.from.platform})` : ''}`;
|
|
22643
22661
|
const toStop = `To: ${leg.to.name}${leg.to.platform ? ` (Pl. ${leg.to.platform})` : ''}`;
|
|
22644
22662
|
const transferDetails = 'type' in leg && !('route' in leg)
|
|
22645
|
-
? `Transfer: ${leg.type}${leg.minTransferTime ? `, Minimum Transfer Time: ${durationToString(leg.minTransferTime)}` : ''}`
|
|
22663
|
+
? `Transfer: ${transferTypeToString(leg.type)}${leg.minTransferTime ? `, Minimum Transfer Time: ${durationToString(leg.minTransferTime)}` : ''}`
|
|
22646
22664
|
: '';
|
|
22647
22665
|
const accessDetails = 'duration' in leg
|
|
22648
22666
|
? `Access duration: ${durationToString(leg.duration)}`
|
|
22649
22667
|
: '';
|
|
22650
22668
|
const travelDetails = 'route' in leg && 'departureTime' in leg && 'arrivalTime' in leg
|
|
22651
|
-
? `Route: ${leg.route.type} ${leg.route.name}, Departure: ${timeToString(leg.departureTime)}, Arrival: ${timeToString(leg.arrivalTime)}`
|
|
22669
|
+
? `Route: ${routeTypeToString(leg.route.type)} ${leg.route.name}, Departure: ${timeToString(leg.departureTime)}, Arrival: ${timeToString(leg.arrivalTime)}`
|
|
22652
22670
|
: '';
|
|
22653
22671
|
return [
|
|
22654
22672
|
`Leg ${index + 1}:`,
|
|
@@ -22665,30 +22683,6 @@ class Route {
|
|
|
22665
22683
|
}
|
|
22666
22684
|
}
|
|
22667
22685
|
|
|
22668
|
-
/**
|
|
22669
|
-
* Details about the pickup and drop-off modalities at each stop in each trip of a route.
|
|
22670
|
-
*/
|
|
22671
|
-
const pickUpDropOffTypeMap = [
|
|
22672
|
-
'REGULAR',
|
|
22673
|
-
'NOT_AVAILABLE',
|
|
22674
|
-
'MUST_PHONE_AGENCY',
|
|
22675
|
-
'MUST_COORDINATE_WITH_DRIVER',
|
|
22676
|
-
];
|
|
22677
|
-
/**
|
|
22678
|
-
* Converts a numerical representation of a pick-up/drop-off type
|
|
22679
|
-
* into its corresponding string representation.
|
|
22680
|
-
*
|
|
22681
|
-
* @param numericalType - The numerical value representing the pick-up/drop-off type.
|
|
22682
|
-
* @returns The corresponding PickUpDropOffTypeString as a string.
|
|
22683
|
-
* @throws An error if the numerical type is invalid.
|
|
22684
|
-
*/
|
|
22685
|
-
const toPickupDropOffType = (rawType) => {
|
|
22686
|
-
const type = pickUpDropOffTypeMap[rawType];
|
|
22687
|
-
if (!type) {
|
|
22688
|
-
throw new Error(`Invalid pickup/drop-off type ${rawType}`);
|
|
22689
|
-
}
|
|
22690
|
-
return type;
|
|
22691
|
-
};
|
|
22692
22686
|
class Result {
|
|
22693
22687
|
constructor(destinations, routingState, stopsIndex, timetable) {
|
|
22694
22688
|
this.destinations = destinations;
|
|
@@ -22838,7 +22832,7 @@ class Result {
|
|
|
22838
22832
|
buildServiceRouteInfo(route) {
|
|
22839
22833
|
const serviceRouteInfo = this.timetable.getServiceRouteInfo(route);
|
|
22840
22834
|
return {
|
|
22841
|
-
type:
|
|
22835
|
+
type: serviceRouteInfo.type,
|
|
22842
22836
|
name: serviceRouteInfo.name,
|
|
22843
22837
|
};
|
|
22844
22838
|
}
|
|
@@ -22872,8 +22866,8 @@ class Result {
|
|
|
22872
22866
|
route: this.buildServiceRouteInfo(firstRoute),
|
|
22873
22867
|
departureTime: firstRoute.departureFrom(firstEdge.stopIndex, firstEdge.tripIndex),
|
|
22874
22868
|
arrivalTime: lastEdge.arrival,
|
|
22875
|
-
pickUpType:
|
|
22876
|
-
dropOffType:
|
|
22869
|
+
pickUpType: firstRoute.pickUpTypeFrom(firstEdge.stopIndex, firstEdge.tripIndex),
|
|
22870
|
+
dropOffType: lastRoute.dropOffTypeAt(lastEdge.hopOffStopIndex, lastEdge.tripIndex),
|
|
22877
22871
|
};
|
|
22878
22872
|
}
|
|
22879
22873
|
/**
|
|
@@ -22889,7 +22883,7 @@ class Result {
|
|
|
22889
22883
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
22890
22884
|
to: this.stopsIndex.findStopById(edge.to),
|
|
22891
22885
|
minTransferTime: edge.minTransferTime,
|
|
22892
|
-
type:
|
|
22886
|
+
type: edge.type,
|
|
22893
22887
|
};
|
|
22894
22888
|
}
|
|
22895
22889
|
/**
|
|
@@ -22926,7 +22920,7 @@ class Result {
|
|
|
22926
22920
|
from: this.stopsIndex.findStopById(fromStopId),
|
|
22927
22921
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
22928
22922
|
to: this.stopsIndex.findStopById(toStopId),
|
|
22929
|
-
type:
|
|
22923
|
+
type: TransferTypes.GUARANTEED,
|
|
22930
22924
|
};
|
|
22931
22925
|
}
|
|
22932
22926
|
/**
|
|
@@ -23107,8 +23101,8 @@ class RoutingState {
|
|
|
23107
23101
|
*/
|
|
23108
23102
|
this.maxArrivalTime = UNREACHED_TIME;
|
|
23109
23103
|
/**
|
|
23110
|
-
* Every stop
|
|
23111
|
-
*
|
|
23104
|
+
* Every stop reached during the current run, recorded once in first-reached
|
|
23105
|
+
* order. Used by {@link resetFor} to clear
|
|
23112
23106
|
* only the touched entries instead of scanning the entire array.
|
|
23113
23107
|
*/
|
|
23114
23108
|
this.reachedStops = [];
|
|
@@ -23200,7 +23194,9 @@ class RoutingState {
|
|
|
23200
23194
|
* @param leg The round number (number of transit legs taken so far).
|
|
23201
23195
|
*/
|
|
23202
23196
|
updateArrival(stop, time, leg) {
|
|
23203
|
-
this.
|
|
23197
|
+
if (this.earliestArrivalTimes[stop] === UNREACHED_TIME) {
|
|
23198
|
+
this.reachedStops.push(stop);
|
|
23199
|
+
}
|
|
23204
23200
|
this.earliestArrivalTimes[stop] = time;
|
|
23205
23201
|
this.earliestArrivalLegs[stop] = leg;
|
|
23206
23202
|
if (this.destinationSet.has(stop) && time < this._destinationBest) {
|
|
@@ -23338,6 +23334,13 @@ class RoutingState {
|
|
|
23338
23334
|
return arr;
|
|
23339
23335
|
});
|
|
23340
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);
|
|
23341
23344
|
return state;
|
|
23342
23345
|
}
|
|
23343
23346
|
}
|
|
@@ -24114,6 +24117,50 @@ class Router {
|
|
|
24114
24117
|
}
|
|
24115
24118
|
}
|
|
24116
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
|
+
};
|
|
24117
24164
|
const renderTable = (columns, rows, footerRow) => {
|
|
24118
24165
|
const bar = (l, m, r) => l + columns.map((c) => '─'.repeat(c.width + 2)).join(m) + r;
|
|
24119
24166
|
const renderRow = (cells) => '│' +
|
|
@@ -24241,32 +24288,12 @@ const loadRangeQueriesFromJson = (filePath, stopsIndex) => {
|
|
|
24241
24288
|
* yield a more stable mean at the cost of longer wall-clock time.
|
|
24242
24289
|
* @param stopsIndex - Used to resolve stop names for result labels.
|
|
24243
24290
|
* @returns An array of {@link PerformanceResult} objects, one per query, each
|
|
24244
|
-
* 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).
|
|
24245
24292
|
*/
|
|
24246
24293
|
const testRouterPerformance = (router, tasks, iterations, stopsIndex) => {
|
|
24247
24294
|
const results = [];
|
|
24248
24295
|
for (const task of tasks) {
|
|
24249
|
-
|
|
24250
|
-
let totalMemory = 0;
|
|
24251
|
-
for (let i = 0; i < iterations; i++) {
|
|
24252
|
-
if (global.gc) {
|
|
24253
|
-
global.gc();
|
|
24254
|
-
}
|
|
24255
|
-
const startMemory = process.memoryUsage().heapUsed;
|
|
24256
|
-
const startTime = performance$1.now();
|
|
24257
|
-
router.route(task);
|
|
24258
|
-
const endTime = performance$1.now();
|
|
24259
|
-
const endMemory = process.memoryUsage().heapUsed;
|
|
24260
|
-
totalTime += (endTime - startTime) * 1000;
|
|
24261
|
-
if (endMemory >= startMemory) {
|
|
24262
|
-
totalMemory += endMemory - startMemory;
|
|
24263
|
-
}
|
|
24264
|
-
}
|
|
24265
|
-
results.push({
|
|
24266
|
-
label: buildQueryLabel(task, stopsIndex),
|
|
24267
|
-
meanTimeUs: totalTime / iterations,
|
|
24268
|
-
meanMemoryMb: totalMemory / iterations / (1024 * 1024),
|
|
24269
|
-
});
|
|
24296
|
+
results.push(Object.assign({ label: buildQueryLabel(task, stopsIndex) }, measurePerformance(() => router.route(task), iterations)));
|
|
24270
24297
|
}
|
|
24271
24298
|
return results;
|
|
24272
24299
|
};
|
|
@@ -24281,34 +24308,14 @@ const testRouterPerformance = (router, tasks, iterations, stopsIndex) => {
|
|
|
24281
24308
|
* @param iterations - Number of times `bestRoute` is called per query.
|
|
24282
24309
|
* @param stopsIndex - Used to resolve stop names for result labels.
|
|
24283
24310
|
* @returns An array of {@link PerformanceResult} objects, one per query, each
|
|
24284
|
-
* 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
|
|
24285
24312
|
* `bestRoute` call alone.
|
|
24286
24313
|
*/
|
|
24287
24314
|
const testBestRoutePerformance = (router, tasks, iterations, stopsIndex) => {
|
|
24288
24315
|
const results = [];
|
|
24289
24316
|
for (const task of tasks) {
|
|
24290
24317
|
const result = router.route(task);
|
|
24291
|
-
|
|
24292
|
-
let totalMemory = 0;
|
|
24293
|
-
for (let i = 0; i < iterations; i++) {
|
|
24294
|
-
if (global.gc) {
|
|
24295
|
-
global.gc();
|
|
24296
|
-
}
|
|
24297
|
-
const startMemory = process.memoryUsage().heapUsed;
|
|
24298
|
-
const startTime = performance$1.now();
|
|
24299
|
-
result.bestRoute();
|
|
24300
|
-
const endTime = performance$1.now();
|
|
24301
|
-
const endMemory = process.memoryUsage().heapUsed;
|
|
24302
|
-
totalTime += (endTime - startTime) * 1000;
|
|
24303
|
-
if (endMemory >= startMemory) {
|
|
24304
|
-
totalMemory += endMemory - startMemory;
|
|
24305
|
-
}
|
|
24306
|
-
}
|
|
24307
|
-
results.push({
|
|
24308
|
-
label: buildQueryLabel(task, stopsIndex),
|
|
24309
|
-
meanTimeUs: totalTime / iterations,
|
|
24310
|
-
meanMemoryMb: totalMemory / iterations / (1024 * 1024),
|
|
24311
|
-
});
|
|
24318
|
+
results.push(Object.assign({ label: buildQueryLabel(task, stopsIndex) }, measurePerformance(() => result.bestRoute(), iterations)));
|
|
24312
24319
|
}
|
|
24313
24320
|
return results;
|
|
24314
24321
|
};
|
|
@@ -24321,32 +24328,12 @@ const testBestRoutePerformance = (router, tasks, iterations, stopsIndex) => {
|
|
|
24321
24328
|
* @param iterations - Number of times each query is repeated.
|
|
24322
24329
|
* @param stopsIndex - Used to resolve stop names for result labels.
|
|
24323
24330
|
* @returns An array of {@link PerformanceResult} objects, one per query, each
|
|
24324
|
-
* 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).
|
|
24325
24332
|
*/
|
|
24326
24333
|
const testRangeRouterPerformance = (router, tasks, iterations, stopsIndex) => {
|
|
24327
24334
|
const results = [];
|
|
24328
24335
|
for (const task of tasks) {
|
|
24329
|
-
|
|
24330
|
-
let totalMemory = 0;
|
|
24331
|
-
for (let i = 0; i < iterations; i++) {
|
|
24332
|
-
if (global.gc) {
|
|
24333
|
-
global.gc();
|
|
24334
|
-
}
|
|
24335
|
-
const startMemory = process.memoryUsage().heapUsed;
|
|
24336
|
-
const startTime = performance$1.now();
|
|
24337
|
-
router.rangeRoute(task);
|
|
24338
|
-
const endTime = performance$1.now();
|
|
24339
|
-
const endMemory = process.memoryUsage().heapUsed;
|
|
24340
|
-
totalTime += (endTime - startTime) * 1000;
|
|
24341
|
-
if (endMemory >= startMemory) {
|
|
24342
|
-
totalMemory += endMemory - startMemory;
|
|
24343
|
-
}
|
|
24344
|
-
}
|
|
24345
|
-
results.push({
|
|
24346
|
-
label: buildQueryLabel(task, stopsIndex),
|
|
24347
|
-
meanTimeUs: totalTime / iterations,
|
|
24348
|
-
meanMemoryMb: totalMemory / iterations / (1024 * 1024),
|
|
24349
|
-
});
|
|
24336
|
+
results.push(Object.assign({ label: buildQueryLabel(task, stopsIndex) }, measurePerformance(() => router.rangeRoute(task), iterations)));
|
|
24350
24337
|
}
|
|
24351
24338
|
return results;
|
|
24352
24339
|
};
|
|
@@ -24361,38 +24348,17 @@ const testRangeRouterPerformance = (router, tasks, iterations, stopsIndex) => {
|
|
|
24361
24348
|
* @param iterations - Number of times `getRoutes` is called per query.
|
|
24362
24349
|
* @param stopsIndex - Used to resolve stop names for result labels.
|
|
24363
24350
|
* @returns An array of {@link PerformanceResult} objects, one per query, each
|
|
24364
|
-
* 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
|
|
24365
24352
|
* `getRoutes` call alone.
|
|
24366
24353
|
*/
|
|
24367
24354
|
const testRangeResultPerformance = (router, tasks, iterations, stopsIndex) => {
|
|
24368
24355
|
const results = [];
|
|
24369
24356
|
for (const task of tasks) {
|
|
24370
24357
|
const rangeResult = router.rangeRoute(task);
|
|
24371
|
-
|
|
24372
|
-
let totalMemory = 0;
|
|
24373
|
-
for (let i = 0; i < iterations; i++) {
|
|
24374
|
-
if (global.gc) {
|
|
24375
|
-
global.gc();
|
|
24376
|
-
}
|
|
24377
|
-
const startMemory = process.memoryUsage().heapUsed;
|
|
24378
|
-
const startTime = performance$1.now();
|
|
24379
|
-
rangeResult.getRoutes();
|
|
24380
|
-
const endTime = performance$1.now();
|
|
24381
|
-
const endMemory = process.memoryUsage().heapUsed;
|
|
24382
|
-
totalTime += (endTime - startTime) * 1000;
|
|
24383
|
-
if (endMemory >= startMemory) {
|
|
24384
|
-
totalMemory += endMemory - startMemory;
|
|
24385
|
-
}
|
|
24386
|
-
}
|
|
24387
|
-
results.push({
|
|
24388
|
-
label: buildQueryLabel(task, stopsIndex),
|
|
24389
|
-
meanTimeUs: totalTime / iterations,
|
|
24390
|
-
meanMemoryMb: totalMemory / iterations / (1024 * 1024),
|
|
24391
|
-
});
|
|
24358
|
+
results.push(Object.assign({ label: buildQueryLabel(task, stopsIndex) }, measurePerformance(() => rangeResult.getRoutes(), iterations)));
|
|
24392
24359
|
}
|
|
24393
24360
|
return results;
|
|
24394
24361
|
};
|
|
24395
|
-
// ─── Output ───────────────────────────────────────────────────────────────────
|
|
24396
24362
|
/**
|
|
24397
24363
|
* Prints a table summary of performance results to stdout.
|
|
24398
24364
|
*
|
|
@@ -24412,12 +24378,16 @@ const prettyPrintPerformanceResults = (results, label = 'Performance Results') =
|
|
|
24412
24378
|
const fmtTime = (n) => Math.round(n).toLocaleString('en-US');
|
|
24413
24379
|
const fmtMem = (n) => n.toFixed(2);
|
|
24414
24380
|
const meanTime = results.reduce((s, r) => s + r.meanTimeUs, 0) / results.length;
|
|
24415
|
-
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;
|
|
24416
24383
|
const queryHeader = 'Query';
|
|
24417
24384
|
const timeHeader = 'Time (µs)';
|
|
24418
|
-
const memHeader = '
|
|
24385
|
+
const memHeader = 'Heap Δ (MiB)';
|
|
24386
|
+
const buffersHeader = 'ArrayBuffers Δ (MiB)';
|
|
24419
24387
|
const timeVals = results.map((r) => fmtTime(r.meanTimeUs));
|
|
24420
|
-
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);
|
|
24421
24391
|
const meanTimeStr = fmtTime(meanTime);
|
|
24422
24392
|
const meanMemStr = fmtMem(meanMem);
|
|
24423
24393
|
const queryWidth = Math.max(queryHeader.length, 'mean'.length, ...results.map((r) => r.label.length));
|
|
@@ -24427,17 +24397,26 @@ const prettyPrintPerformanceResults = (results, label = 'Performance Results') =
|
|
|
24427
24397
|
{ header: queryHeader, width: queryWidth, align: 'left' },
|
|
24428
24398
|
{ header: timeHeader, width: timeWidth, align: 'right' },
|
|
24429
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
|
+
},
|
|
24430
24405
|
];
|
|
24431
24406
|
const rows = results.map((r, i) => {
|
|
24432
|
-
var _a, _b;
|
|
24407
|
+
var _a, _b, _c;
|
|
24433
24408
|
return [
|
|
24434
24409
|
r.label,
|
|
24435
24410
|
(_a = timeVals[i]) !== null && _a !== void 0 ? _a : '',
|
|
24436
24411
|
(_b = memVals[i]) !== null && _b !== void 0 ? _b : '',
|
|
24412
|
+
(_c = bufferVals[i]) !== null && _c !== void 0 ? _c : '',
|
|
24437
24413
|
];
|
|
24438
24414
|
});
|
|
24439
|
-
const footer = ['mean', meanTimeStr, meanMemStr];
|
|
24415
|
+
const footer = ['mean', meanTimeStr, meanMemStr, meanBuffersStr];
|
|
24440
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
|
+
}
|
|
24441
24420
|
};
|
|
24442
24421
|
|
|
24443
24422
|
/**
|
|
@@ -24729,7 +24708,7 @@ const startRepl = (stopsPath, timetablePath) => {
|
|
|
24729
24708
|
}
|
|
24730
24709
|
const serviceRouteInfo = timetable.getServiceRouteInfo(route);
|
|
24731
24710
|
const routeName = serviceRouteInfo.name;
|
|
24732
|
-
const routeType = serviceRouteInfo.type;
|
|
24711
|
+
const routeType = routeTypeToString(serviceRouteInfo.type);
|
|
24733
24712
|
console.log(`\n=== Route ${routeId} ===`);
|
|
24734
24713
|
console.log(`Service Route: ${routeName}`);
|
|
24735
24714
|
console.log(`Type: ${routeType}`);
|
|
@@ -24809,7 +24788,7 @@ const startRepl = (stopsPath, timetablePath) => {
|
|
|
24809
24788
|
console.log('\n--- Routes ---');
|
|
24810
24789
|
routes.forEach((route, index) => {
|
|
24811
24790
|
const serviceRouteInfo = timetable.getServiceRouteInfo(route);
|
|
24812
|
-
console.log(`${index + 1}. Route ${route.id}: ${serviceRouteInfo.name} (${serviceRouteInfo.type})`);
|
|
24791
|
+
console.log(`${index + 1}. Route ${route.id}: ${serviceRouteInfo.name} (${routeTypeToString(serviceRouteInfo.type)})`);
|
|
24813
24792
|
});
|
|
24814
24793
|
}
|
|
24815
24794
|
const transfers = timetable.getTransfers(stop.id);
|
|
@@ -24825,7 +24804,7 @@ const startRepl = (stopsPath, timetablePath) => {
|
|
|
24825
24804
|
const minTime = transfer.minTransferTime
|
|
24826
24805
|
? ` (min: ${transfer.minTransferTime}min)`
|
|
24827
24806
|
: '';
|
|
24828
|
-
console.log(`${index + 1}. ${transfer.type} to ${(_a = destStop === null || destStop === void 0 ? void 0 : destStop.name) !== null && _a !== void 0 ? _a : 'Unknown'}${platform} (${transfer.destination}, ${(_b = destStop === null || destStop === void 0 ? void 0 : destStop.sourceStopId) !== null && _b !== void 0 ? _b : 'N/A'})${minTime}`);
|
|
24807
|
+
console.log(`${index + 1}. ${transferTypeToString(transfer.type)} to ${(_a = destStop === null || destStop === void 0 ? void 0 : destStop.name) !== null && _a !== void 0 ? _a : 'Unknown'}${platform} (${transfer.destination}, ${(_b = destStop === null || destStop === void 0 ? void 0 : destStop.sourceStopId) !== null && _b !== void 0 ? _b : 'N/A'})${minTime}`);
|
|
24829
24808
|
});
|
|
24830
24809
|
}
|
|
24831
24810
|
let totalContinuations = 0;
|
|
@@ -24978,7 +24957,16 @@ program
|
|
|
24978
24957
|
.option('-i, --iterations <number>', 'Number of iterations for performance tests', '20')
|
|
24979
24958
|
.action((routesPath, options) => {
|
|
24980
24959
|
const stopsIndex = StopsIndex.fromData(fs$1.readFileSync(options.stopsPath));
|
|
24981
|
-
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
|
+
}
|
|
24982
24970
|
const router = new Router(timetable, stopsIndex);
|
|
24983
24971
|
const queries = loadQueriesFromJson(routesPath, stopsIndex);
|
|
24984
24972
|
const iterations = parseInt(options.iterations, 10);
|