-
Notifications
You must be signed in to change notification settings - Fork 59
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
Prevent memory allocation during scaleAddOffset if it's unneeded #72
Merged
BobSimons
merged 1 commit into
ERDDAP:master
from
ChrisJohnNOAA:scaleAddOffsettHeapSavings
May 4, 2022
Merged
Prevent memory allocation during scaleAddOffset if it's unneeded #72
BobSimons
merged 1 commit into
ERDDAP:master
from
ChrisJohnNOAA:scaleAddOffsettHeapSavings
May 4, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I looked everywhere this is used and generally the result of the call is used to overwrite the PA that is provided as a parameter, so returning the same PA is not an issue. During EDDGridFromNcFiles.testBigRequestSpeed this prevents the unnecesary allocation of multiple 37324800 item PrimitiveArrays which will reduce the need for garbage collection.
I realized scaleAddOffset is more complicated than I originally thought.
I think the point of the "always" in the original documentation for this
method ("This returns a new (always) PrimitiveArray") isn't so much that
the returned primitive array will always be a new PrimitiveArray. It is
that the values in the source array won't be changed and, by always
returning a new array, we are thus assured that the values in the source
array won't ever be changed. As a general note: when I say something
pointed in the documentation (like "always"), there's often a reason.
I think (but could easily be wrong) that this method is used in two main
ways:
1) to modify the PrimitiveArray attribute associated with an attribute when
generating the combinedAttributes (from the sourceAttributes +
addAttributes). These are tiny PrimitiveArrays and we don't want the
sourceAttributes to be changed. There is little cost to making a clone of
the source array before calling this method.
2) to modify a data PrimitiveArray when fulfilling a request. These can be
huge and it is fine if the source PrimitiveArray is changed.
I hope that makes sense. Let's keep the changes you made to this method.
But, in light of this information, can you please review the uses of
scaleAddOffset and add something like
pa = (PrimitiveArray)pa.clone();
before calling scaleAddOffset for situations like (1) above?
Or if you think that is already handled one way or another, let me know.
Thanks.
I said yesterday that this job was basically low pressure. I realized there
is one underlying pressure: not to make a mistake that leads to incorrect
results. I doubt if anyone is double checking the results in the way that
the unit tests do, so an error that we don't catch could go undetected for
years. That would be really bad and destroy people's trust in ERDDAP. So
I've tried hard not to make any errors like that.
I just thought I should say that even though it's probably obvious.
Best wishes.
…On Mon, May 2, 2022 at 2:32 PM Chris John ***@***.***> wrote:
I looked everywhere this is used and generally the result of the call is
used to overwrite the PA that is provided as a parameter, so returning the
same PA is not an issue.
During EDDGridFromNcFiles.testBigRequestSpeed this prevents the unnecesary
allocation of multiple 37324800 item PrimitiveArrays which will reduce the
need for garbage collection.
------------------------------
You can view, comment on, or merge this pull request online at:
#72
Commit Summary
- 7c302b0
<7c302b0>
Prevent memory allocation during scaleAddOffset if it's unneeded
File Changes
(1 file <https://github.com/BobSimons/erddap/pull/72/files>)
- *M* WEB-INF/classes/com/cohort/array/PrimitiveArray.java
<https://github.com/BobSimons/erddap/pull/72/files#diff-9e30d7d869bead84c7bf0ce2d96a86cc19735a892806cb78bbfdee0cabae6339>
(10)
Patch Links:
- https://github.com/BobSimons/erddap/pull/72.patch
- https://github.com/BobSimons/erddap/pull/72.diff
—
Reply to this email directly, view it on GitHub
<#72>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALKWOCBCDQHTSYG33T4FK3VIANSHANCNFSM5U4XVE5A>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
BobSimons
pushed a commit
that referenced
this pull request
May 13, 2022
…ed to return a new PrimitiveArray (re #72).
ChrisJohnNOAA
pushed a commit
to ChrisJohnNOAA/erddap
that referenced
this pull request
Apr 28, 2023
Prevent memory allocation during scaleAddOffset if it's unneeded
ChrisJohnNOAA
pushed a commit
to ChrisJohnNOAA/erddap
that referenced
this pull request
Apr 28, 2023
…ed to return a new PrimitiveArray (re ERDDAP#72).
ChrisJohnNOAA
pushed a commit
that referenced
this pull request
Jun 1, 2023
Prevent memory allocation during scaleAddOffset if it's unneeded
ChrisJohnNOAA
pushed a commit
that referenced
this pull request
Jun 1, 2023
…ed to return a new PrimitiveArray (re #72).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I looked everywhere this is used and generally the result of the call is used to overwrite the PA that is provided as a parameter, so returning the same PA is not an issue.
During EDDGridFromNcFiles.testBigRequestSpeed this prevents the unnecesary allocation of multiple 37324800 item PrimitiveArrays which will reduce the need for garbage collection.