mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 06:51:17 +07:00
[workspace model] IDEA-CR-71323 Avoid Kryo#referenceResolver reset after an entire object graph has been read
This option allows us to reuse objects which were previously read instead of creating a new instances GitOrigin-RevId: 693399481040e04d4f5c0aee90f8af86e4d97877
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c6a308b460
commit
211330d890
@@ -13,7 +13,6 @@ import com.intellij.project.isDirectoryBased
|
||||
import com.intellij.workspaceModel.storage.EntitySource
|
||||
import com.intellij.workspaceModel.storage.url.VirtualFileUrl
|
||||
import com.intellij.workspaceModel.storage.url.VirtualFileUrlManager
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.jps.util.JpsPathUtil
|
||||
@@ -161,19 +160,14 @@ fun getJpsProjectConfigLocation(project: Project): JpsProjectConfigLocation? {
|
||||
}
|
||||
|
||||
internal class FileInDirectorySerializer : Serializer<JpsFileEntitySource.FileInDirectory>(false, true) {
|
||||
// We should not care of this collection cleanup because each serialization/deserialization creates it's own instance of Kryo
|
||||
private val oldFileNameIdToNewEntitySource = Int2ObjectOpenHashMap<JpsFileEntitySource.FileInDirectory>()
|
||||
|
||||
override fun write(kryo: Kryo, output: Output, o: JpsFileEntitySource.FileInDirectory) {
|
||||
kryo.writeClassAndObject(output, o.directory)
|
||||
kryo.writeClassAndObject(output, o.fileNameId)
|
||||
kryo.writeClassAndObject(output, o.projectLocation)
|
||||
}
|
||||
|
||||
override fun read(kryo: Kryo, input: Input, type: Class<JpsFileEntitySource.FileInDirectory>): JpsFileEntitySource.FileInDirectory {
|
||||
val fileUrl = kryo.readClassAndObject(input) as VirtualFileUrl
|
||||
val oldFileNameId = kryo.readClassAndObject(input) as Int
|
||||
val location = kryo.readClassAndObject(input) as JpsProjectConfigLocation
|
||||
return oldFileNameIdToNewEntitySource.getOrPut(oldFileNameId) { JpsFileEntitySource.FileInDirectory(fileUrl, location) }
|
||||
return JpsFileEntitySource.FileInDirectory(fileUrl, location)
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -39,14 +39,14 @@ class ImlSerializationTest {
|
||||
|
||||
@Test
|
||||
fun sizeCheck() {
|
||||
val expectedSize = 47_000
|
||||
val expectedSize = 26_000
|
||||
val projectDir = File(PathManagerEx.getCommunityHomePath(), "jps/model-serialization/testData/sampleProject")
|
||||
val bytes = loadProjectAndCheck(projectDir)
|
||||
|
||||
checkSerializationSize(bytes, expectedSize, 2_000)
|
||||
|
||||
assertTrue("This assertion is a reminder. Have you updated the serializer? Update the serializer version!",
|
||||
47_000 == expectedSize && "v15" == EntityStorageSerializerImpl.SERIALIZER_VERSION)
|
||||
26_000 == expectedSize && "v16" == EntityStorageSerializerImpl.SERIALIZER_VERSION)
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-1
@@ -40,7 +40,7 @@ private val LOG = logger<EntityStorageSerializerImpl>()
|
||||
class EntityStorageSerializerImpl(private val typesResolver: EntityTypesResolver,
|
||||
private val virtualFileManager: VirtualFileUrlManager) : EntityStorageSerializer {
|
||||
companion object {
|
||||
const val SERIALIZER_VERSION = "v15"
|
||||
const val SERIALIZER_VERSION = "v16"
|
||||
}
|
||||
|
||||
private val KRYO_BUFFER_SIZE = 64 * 1024
|
||||
@@ -51,6 +51,7 @@ class EntityStorageSerializerImpl(private val typesResolver: EntityTypesResolver
|
||||
internal fun createKryo(): Kryo {
|
||||
val kryo = Kryo()
|
||||
|
||||
kryo.setAutoReset(false)
|
||||
kryo.isRegistrationRequired = true
|
||||
kryo.instantiatorStrategy = StdInstantiatorStrategy()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user