Skip to content

Conversation

@jush
Copy link
Member

@jush jush commented Jan 26, 2026

Avoid using List<Double> for Point. Instead use double [].

Moreover, expose accessors to the flatten structure.

This change improves memory usage significantly:

Before: using List After: using double []
3M list of points take 286,1MB 3M double [] points take 45,8MB
non-optimized-list-points optimized-list-points

if (altitudes == null) {
altitudes = new double[points.size()];
// Fill in any previous altitude as NaN
for (int j = 0; j < i; j++) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just pre-fill all array with NaN and then set valid values on top of it during i cycle?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would result in unnecessary CPU cycles for the non-NaN future ones.

I don't have hard numbers but I would imagine that if the points have altitude I guess most of them will have it. I think (again no evidence) the pattern will be that either there's altitude for all points or there's none.

Or is there a fast way to pre-fill with NaN? without iterating one by one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants