You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
JAVA-2303: Improve performance of LazyBSONObject.entrySet and hashCode
The root cause of the performance problem was that the entrySet
implementation inserted all the entries into an actual HashSet,
which in turn called hashCode on all embedded LazyBSONOBject
instances. The hashCode implemenation examined every byte in the
array instead of just the bytes between offset and size.
The fix is two-fold. The first is to use a private Set implementation
for the entrySet that just wraps an ArrayList and therefore doesn't
need to call hashCode anymore at all. While calls to entrySet().contains
and entrySet().containsAll will be slower, that is an acceptable trade-off
as usage of those methods is likely to be rare.
The second change is to ensure that LazyBSONObject.hashCode only examines the
bytes between offset and size, just in case clients are sticking instances in
their own hash tables.
0 commit comments