ehcache / sizeof

Configurable sizeOf engine for Ehcache
Apache License 2.0
105 stars 43 forks source link

Avoid double lookup in the visited `IdentityHashMap` #56

Closed alexsnaps closed 6 years ago

alexsnaps commented 6 years ago

In the ObjectGraphWalker's hot loop, we look up if the key is absent from the visited: IdentityHashMap before doing work, to then add it at the end… This PR avoids the double look up by adding the entry first, with a marker object as value, and in case the key was already present we skip it. Avoiding the double lookup in the case the reference hadn't been encountered yet (i.e. probably most cases)