Skip to content
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

[ClusterStats] compute lazily #645

Open
vicb opened this issue May 24, 2023 · 0 comments
Open

[ClusterStats] compute lazily #645

vicb opened this issue May 24, 2023 · 0 comments
Labels
good first issue This issue is a good place to started contributing to this repository. priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@vicb
Copy link
Contributor

vicb commented May 24, 2023

As of today the stats are computed eagerly as they are constructed:

constructor(markers: Marker[], clusters: Cluster[]) {
this.markers = { sum: markers.length };
const clusterMarkerCounts = clusters.map((a) => a.count);
const clusterMarkerSum = clusterMarkerCounts.reduce((a, b) => a + b, 0);
this.clusters = {
count: clusters.length,
markers: {
mean: clusterMarkerSum / clusters.length,
sum: clusterMarkerSum,
min: Math.min(...clusterMarkerCounts),
max: Math.max(...clusterMarkerCounts),
},
};
}
}

That's wasted CPU cycles when the stats are not required (i.e. with a custom renderer).

We should compute the stats lazily when one of the markers's property is first accessed to avoid that.

This could be done in a backward compatible way using getters.

@vicb vicb added triage me I really want to be triaged. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels May 24, 2023
@usefulthink usefulthink added priority: p3 Desirable enhancement or fix. May not be included in next release. good first issue This issue is a good place to started contributing to this repository. and removed triage me I really want to be triaged. labels Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue This issue is a good place to started contributing to this repository. priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

3 participants