mirror of
https://github.com/ysoftdevs/odc-analyzer.git
synced 2026-03-25 10:32:28 +01:00
Drastically reduced memory usage, mostly using deduplication.
This commit is contained in:
25
app/com/ysoft/debug/KnownObjects.scala
Normal file
25
app/com/ysoft/debug/KnownObjects.scala
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.ysoft.debug
|
||||
|
||||
import java.util
|
||||
|
||||
import com.google.caliper.memory.ObjectVisitor.Traversal
|
||||
import play.api.Logger
|
||||
|
||||
// We use Java collections because they can have the initial size configured
|
||||
case class KnownObjects(
|
||||
objSet: java.util.HashSet[Any] = new util.HashSet[Any](),
|
||||
identitiesSet: java.util.Set[Any] = java.util.Collections.newSetFromMap(new util.IdentityHashMap[Any, java.lang.Boolean]())
|
||||
){
|
||||
def visit(obj: AnyRef) = {
|
||||
val seen = !identitiesSet.add(obj)
|
||||
if(seen){
|
||||
Traversal.SKIP
|
||||
}else{
|
||||
objSet.add(obj)
|
||||
Traversal.EXPLORE
|
||||
}
|
||||
}
|
||||
|
||||
def stats = (identitiesSet.size, objSet.size)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user