rahul37wallst-sudo commented on code in PR #21699:
URL: https://github.com/apache/echarts/pull/21699#discussion_r3631600352
##########
src/data/Source.ts:
##########
@@ -401,12 +401,23 @@ function determineSourceDimensions(
}
function objectRowsCollectDimensions(data: OptionSourceDataObjectRows):
DimensionDefinitionLoose[] {
- let firstIndex = 0;
- let obj;
- while (firstIndex < data.length && !(obj = data[firstIndex++])) {} //
jshint ignore: line
- if (obj) {
- return keys(obj);
+ const dimensionNameMap = createHashMap<true, DimensionName>();
+ const dimensionsDefine: DimensionDefinitionLoose[] = [];
+
+ for (let i = 0; i < data.length; i++) {
+ const obj = data[i];
+ if (!obj) {
+ continue;
+ }
+ each(keys(obj), function (name) {
+ if (!dimensionNameMap.get(name)) {
+ dimensionNameMap.set(name, true);
+ dimensionsDefine.push(name);
+ }
+ });
}
Review Comment:
Thanks for the suggestion. I ran a local benchmark with 100k object rows on
Windows / Node 22.18.0, using two warmups and nine measured runs.
Median source-creation times:
- Stable shape: previous-like first-row path 0.07 ms; full scan 4.92 ms;
explicit `dataset.dimensions` 0.02 ms.
- Sparse shape with a key appearing only in the final row: previous-like
path 0.02 ms; full scan 5.25 ms; explicit dimensions 0.01 ms.
I also isolated the collector implementation:
- `keys(obj)` plus callback: 38.47 ms stable / 34.86 ms sparse.
- `for...in` plus `hasOwn`: 3.10 ms stable / 3.67 ms sparse.
I updated the implementation to the allocation-free `for...in` loop in
commit `b6ace83a5`. The full scan remains O(total object keys), as required to
discover late sparse fields, but the measured source-initialization overhead
was about 5 ms for 100k three-field rows. Supplying `dataset.dimensions`
continues to bypass the scan.
The focused regression tests, `npm run lint`, `npm run checktype`, and `git
diff --check` all pass.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]