-
Notifications
You must be signed in to change notification settings - Fork 25k
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
Reduce copying in GetSnapshotsOperation#snapshots()
#105765
Reduce copying in GetSnapshotsOperation#snapshots()
#105765
Conversation
No need to create a set (the values are distinct anyway), make a separate synchronized list, populate them both, and finally copy them both again into another concatenated list. We can just make the final list up front.
Pinging @elastic/es-distributed (Team:Distributed) |
Reducing the unnecessary copying here is clearly good in its own right, but this change is also motivated by wanting to take more control over the |
#105769 is what I mean by taking more control of the |
@@ -400,7 +400,7 @@ private void snapshots(String repositoryName, Collection<SnapshotId> snapshotIds | |||
if (cancellableTask.notifyIfCancelled(listener)) { | |||
return; | |||
} | |||
final Set<SnapshotInfo> snapshotSet = new HashSet<>(); | |||
final List<SnapshotInfo> snapshots = new ArrayList<>(snapshotIds.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to create a set (the values are distinct anyway)
snapshotIds
is defined as collection in the method signature
Line 399 in b95cb8c
private void snapshots(String repositoryName, Collection<SnapshotId> snapshotIds, ActionListener<SnapshotsInRepo> listener) { |
that is only called from
Line 378 in b95cb8c
snapshots(repo, toResolve.stream().map(Snapshot::getSnapshotId).toList(), listener); |
where toResolve
Line 328 in b95cb8c
final Set<Snapshot> toResolve = new HashSet<>(); |
is defined as a HashSet. I think it is worth to update the method signature to accept Set<SnapshotId> snapshotIds
to better reflect that there are no duplicates expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know what you mean, but (a) nothing particularly bad happens if there are duplicates here, and (b) we'd have to change that .toList()
into a .collect(Collectors.toSet())
which is quite a bit more expensive. This whole thing will go away eventually anyway so I'd rather leave it as-is for now.
No need to create a set (the values are distinct anyway), make a separate synchronized list, populate them both, and finally copy them both again into another concatenated list. We can just make the final list up front.
No need to create a set (the values are distinct anyway), make a
separate synchronized list, populate them both, and finally copy them
both again into another concatenated list. We can just make the final
list up front.