-
Notifications
You must be signed in to change notification settings - Fork 17
553 feature request graphical timetable streckengrafik performance optimisation #555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
553 feature request graphical timetable streckengrafik performance optimisation #555
Conversation
…. To improve rendering performance, we’ve introduced a lookup cache that handles frequent access more efficiently.
shenriotpro
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't say I understand the logic, but I love the result :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR optimizes the performance of the graphical timetable rendering by introducing caching and more efficient data structures, achieving ~3x improvement in Chrome and ~5x improvement in Edge for the extractSectionTracks method.
Key changes:
- Introduced a
Map<number, TrainrunSection>cache to eliminate redundant service calls during rendering - Replaced
number[][]withUint8Arrayfor the data matrix to reduce memory usage and improve access speed - Refactored the track extraction logic into smaller, more focused methods with precomputed values
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return; | ||
| } | ||
|
|
||
| // prepare fast look (cache for big netzgrafik) |
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected incomplete comment 'prepare fast look' to 'prepare fast lookup'.
| // prepare fast look (cache for big netzgrafik) | |
| // prepare fast lookup (cache for big netzgrafik) |
| // We restrict the number of section tracks to 255 tracks (between two nodes we could only | ||
| // have 255 tracks - this improves the performance |
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment explains why 255 tracks is the limit but doesn't explain the underlying constraint. Consider clarifying why the limit exists (e.g., Uint8Array max value) and whether this is a technical or business constraint.
| // We restrict the number of section tracks to 255 tracks (between two nodes we could only | |
| // have 255 tracks - this improves the performance | |
| // We restrict the number of section tracks to 255 tracks (between two nodes) because we use Uint8Array | |
| // to store track occupancy, and Uint8Array can only store values from 0 to 255. This is a technical constraint, | |
| // not a business constraint, and allows for efficient memory usage and performance. |
| departureMod: number, | ||
| timeRes: number, | ||
| headwayTime: number, | ||
| dataMatrix: any[], |
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter type any[] is too generic. Based on the implementation, this should be typed as Uint8Array[] for better type safety and code clarity.
| dataMatrix: any[], | |
| dataMatrix: Uint8Array[], |
| const startIdx = | ||
| baseTimeCellIdx < 0 ? 0 : baseTimeCellIdx > nTimeCells ? nTimeCells : baseTimeCellIdx; | ||
|
|
||
| // const endIdx = Math.max(0, Math.min(baseTimeCellIdx + bandLength, nTimeCells)); (perf. opt.) |
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the startIdx comment above, this commented-out code should either be removed or the comment should explain why the ternary operator approach is a performance optimization over Math.max/Math.min.
| // const endIdx = Math.max(0, Math.min(baseTimeCellIdx + bandLength, nTimeCells)); (perf. opt.) | |
| // Instead of using: const endIdx = Math.max(0, Math.min(baseTimeCellIdx + bandLength, nTimeCells)); | |
| // we use the ternary operator below for performance reasons, as this code is in a hot loop and | |
| // avoiding function calls (Math.max/Math.min) can be measurably faster in JavaScript/TypeScript. |
Co-authored-by: Copilot <[email protected]>
louisgreiner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.



Description
Graphical Timetable Performance Optimization
The calculation time for the extractSectionTracks method has been significantly reduced:
These optimizations enhance responsiveness and reduce latency across browsers, especially for Edge users.
Performance Improvement: extractSectionTracks Method
Goal: Improve rendering performance of the graphical timetable by introducing caching and more efficient data structures.
Extended Functionality
Caching introduced: Added getTrainrunSectionFromCacheDuringRendering() method using a Map<number, TrainrunSection> to avoid redundant service calls.
Cache integration: The cache is now used across multiple methods:
Performance Improvements
Optimized data structure: Replaced
number[][]withUint8ArrayfordataMatrixto reduce memory usage and improve access speed.Frequency unrolling refactored: New method
extractSectionTracksUnrollFreq()handles train frequency loops more efficiently.Occupation band optimization:
extractSectionTracksFillOccupationBand()fills occupancy data with bounds checking and performance tuning.Logic Enhancements
headwayTimecalculation now uses the cache.Precomputations like
travelTimeIdxPartandbaseTimeCellIdximprove loop performanceIssues
#553
Checklist
documentation/