Optimize memory usage in SlicedMapImpl (used in BindingContext)

In short:
before these changes: Map<SlicedMapKey<slice, key>, value>
after: Map<key, Map<slice, value>> // where for nested Map used lightweight storage UserDataHolder

Before these changes it stored map from SlicedMapKey to value.
Where SlicedMapKey created for each record and store slice and key.
And now it sored map from key to UserDataHolder.
UserDataHolder store map from slice to value.
This commit is contained in:
Zalim Bashorov
2015-05-12 14:32:06 +03:00
parent c7175e1858
commit ecb824386e
11 changed files with 154 additions and 152 deletions
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.codegen;
import com.intellij.openapi.util.Pair;
import kotlin.Function3;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor;
@@ -28,7 +29,6 @@ import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.Method;
import java.util.Collection;
import java.util.Map;
public final class JvmSerializationBindings {
public static final SerializationMappingSlice<FunctionDescriptor, Method> METHOD_FOR_FUNCTION =
@@ -82,13 +82,18 @@ public final class JvmSerializationBindings {
@NotNull
public static JvmSerializationBindings union(@NotNull Collection<JvmSerializationBindings> bindings) {
MutableSlicedMap result = SlicedMapImpl.create();
final MutableSlicedMap result = SlicedMapImpl.create();
for (JvmSerializationBindings binding : bindings) {
for (Map.Entry<SlicedMapKey<?, ?>, ?> entry : binding.map) {
SlicedMapKey<?, ?> key = entry.getKey();
result.put((WritableSlice) key.getSlice(), key.getKey(), entry.getValue());
}
binding.map.forEach(new Function3<WritableSlice, Object, Object, Void>() {
@Override
public Void invoke(WritableSlice slice, Object key, Object value) {
result.put(slice, key, value);
return null;
}
});
}
return new JvmSerializationBindings(result);
}