-
Notifications
You must be signed in to change notification settings - Fork 54
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
H3Core.nonZeroLongArrayToList takes too much memory #68
Comments
Hi, sorry for the delayed response! Yes, I think counting the number of non-zero indexes is a reasonable change. Off hand I don't know the performance of the other option, but I assume you want to make sure it does not keep the entire I'm curious if the result array itself already takes up roughly 8GB memory - is that being shown in your memory profiler with the 8GB of memory already being used? |
I just stumbled across this issue when trying to calculate all H3 indexes on a 2.5km long street. (red line in the image at the bottom)
What's your preferred solution for the problem? I cannot really make a statement on which one's the best regarding performance and memory consumption. One could also solve it using streams:
In terms of readability I'd probably prefer this solution. |
In my case the size of the ArrayList is only one small part of the problem. The actual problem is, that the number returned by maxPolyfillSize is way too big. I opened another issue here: uber/h3#708 |
Trying to polyfill big area with resolution 11. I can see that internally algorithm prepared result
h3-java/src/main/java/com/uber/h3core/H3Core.java
Line 691 in 3a1e9bc
h3-java/src/main/java/com/uber/h3core/H3Core.java
Lines 1242 to 1254 in a500880
As you can see in the stacktrace, result is ready, but it just tries to copy it to ArrayList:
Memory, the arrow shows to the place when
nonZeroLongArrayToList
started :Scala code:
The easiest fix is just to get the total number of non-zero elements and allocate an array with that size and copy elements over. Other solution can be moving all zero elements in the original array to the end of the array and wrap it by ArrayList via
Arrays.asList(array).subList(index, IDX_OF_FIRST_ZERO);
. I can create PR if this sounds good.Thanks.
The text was updated successfully, but these errors were encountered: