-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Optimize large dataset rendering perf
- lazy loading using intersection observer for on-demand graph renders - data sampling to reduce point density for large datasets - chunk loading to prevent browser freezing - memoization and React.memo to prevent unnecessary re-renders - debounced resize handling - feature toggles for fine-tuning optimization parameters
- Loading branch information
1 parent
872ab00
commit 516398c
Showing
3 changed files
with
152 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const FEATURES = { | ||
OPTIMIZED_VISUALIZATION: true, // Toggle for visualization optimizations | ||
DATA_SAMPLING_THRESHOLD: 100, // Number of points above which to apply sampling | ||
PROGRESSIVE_LOADING_CHUNK_SIZE: 100, // Number of points to load in each chunk | ||
RESIZE_DEBOUNCE_MS: 10, // Debounce time for resize events in milliseconds | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Utility function to sample data points | ||
export const sampleData = (data, threshold) => { | ||
if (!Array.isArray(data) || data.length <= threshold) return data; | ||
|
||
const samplingRate = Math.ceil(data.length / threshold); | ||
return data.filter((_, index) => index % samplingRate === 0); | ||
}; | ||
|
||
// Process data in chunks | ||
export const processDataInChunks = (data, chunkSize, callback) => { | ||
let currentIndex = 0; | ||
|
||
const processNextChunk = () => { | ||
const chunk = data.slice(currentIndex, currentIndex + chunkSize); | ||
callback(chunk, currentIndex); | ||
currentIndex += chunkSize; | ||
|
||
if (currentIndex < data.length) { | ||
requestAnimationFrame(processNextChunk); | ||
} | ||
}; | ||
|
||
processNextChunk(); | ||
}; | ||
|
||
// Debounce function | ||
export const debounce = (func, wait) => { | ||
let timeout; | ||
return function executedFunction(...args) { | ||
const later = () => { | ||
clearTimeout(timeout); | ||
func(...args); | ||
}; | ||
clearTimeout(timeout); | ||
timeout = setTimeout(later, wait); | ||
}; | ||
}; |