Copilot commented on code in PR #21601:
URL: https://github.com/apache/echarts/pull/21601#discussion_r3176929743
##########
src/processor/dataSample.ts:
##########
@@ -72,6 +74,16 @@ const indexSampler = function (frame: ArrayLike<number>) {
return Math.round(frame.length / 2);
};
+function countDataInAxisExtent(data: SeriesData, baseAxis: Axis, baseDim:
string) {
+ let count = 0;
+ data.each(baseDim, function (value: number) {
+ if (baseAxis.containData(value)) {
Review Comment:
`countDataInAxisExtent` calls `baseAxis.containData` for every data item.
`containData` parses the value via `scale.parse` each time, which can be a
noticeable overhead for large series. Since `data.each(baseDim, …)` yields
already-parsed store values for coord dims (time/value/ordinal on coord),
consider using `const scale = baseAxis.scale; const [min, max] =
scale.getExtent();` and doing a direct numeric range check (or
`scale.contain(value as number)`) to avoid repeated parsing inside the hot loop.
##########
src/processor/dataSample.ts:
##########
@@ -86,14 +98,15 @@ export default function dataSample(seriesType: string):
StageHandler {
const coordSys = seriesModel.coordinateSystem;
const count = data.count();
// Only cartesian2d support down sampling. Disable it when there
is few data.
- if (count > 10 && coordSys.type === 'cartesian2d' && sampling) {
+ if (count > 10 && coordSys.type === 'cartesian2d' && sampling &&
sampling !== 'none') {
const baseAxis = coordSys.getBaseAxis();
const valueAxis = coordSys.getOtherAxis(baseAxis);
const extent = baseAxis.getExtent();
const dpr = api.getDevicePixelRatio();
// Coordinste system has been resized
const size = Math.abs(extent[1] - extent[0]) * (dpr || 1);
Review Comment:
`dataCount` is computed by scanning the entire dataset in
`countDataInAxisExtent`, even in cases where sampling can’t possibly happen.
Since `dataCount <= count`, if `count <= size` then `rate <= 1` regardless of
zoom/filterMode, so this extra pass can be skipped. Consider adding a fast-path
before calling `countDataInAxisExtent` (e.g., bail out early when `count <=
size`) to avoid unnecessary O(n) work in common cases.
--
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]