From c8a7a4ed29b12178a3ec19cb54acc0febb9d05d2 Mon Sep 17 00:00:00 2001 From: Ruslan Cheremin Date: Wed, 31 Jul 2024 00:45:01 +0200 Subject: [PATCH] [indexes] skip useless byte[] allocation/copy + directly use byte[] subrange instead of its copy GitOrigin-RevId: be7ea5c8763e69afa1410171856bb0389f34d434 --- .../src/com/intellij/util/concurrency/propagation.kt | 1 + .../platform/util/io/storages/DataExternalizerEx.java | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/platform/util/src/com/intellij/util/concurrency/propagation.kt b/platform/util/src/com/intellij/util/concurrency/propagation.kt index 21e82070d4d6..62e1aee65f9e 100644 --- a/platform/util/src/com/intellij/util/concurrency/propagation.kt +++ b/platform/util/src/com/intellij/util/concurrency/propagation.kt @@ -268,6 +268,7 @@ internal fun capturePropagationContext(r: Runnable, forceUseContextJob : Boolean } val (childContext, childContinuation) = if (forceUseContextJob) createChildContextWithContextJob(r.toString()) + //TODO: do we really need .toString() here? It allocates ~6 Gb during indexing else createChildContext(r.toString()) command = ContextRunnable(true, childContext, command) if (childContinuation != null) { diff --git a/platform/util/storages/src/com/intellij/platform/util/io/storages/DataExternalizerEx.java b/platform/util/storages/src/com/intellij/platform/util/io/storages/DataExternalizerEx.java index df53f0c4c6fe..7c4bcad6bdc0 100644 --- a/platform/util/storages/src/com/intellij/platform/util/io/storages/DataExternalizerEx.java +++ b/platform/util/storages/src/com/intellij/platform/util/io/storages/DataExternalizerEx.java @@ -117,6 +117,14 @@ public interface DataExternalizerEx { return new ByteArrayWriter(bytes, 0, bytes.length); } + static KnownSizeRecordWriter fromBytes(@NotNull ByteArraySequence bytes) { + return new ByteArrayWriter( + bytes.getInternalBuffer(), + bytes.getOffset(), + bytes.getLength() + ); + } + static KnownSizeRecordWriter fromBytes(byte @NotNull [] bytes, int offset, int length) { @@ -161,7 +169,7 @@ public interface DataExternalizerEx { @Override public String toString() { - return "ByteArrayWriter[" + IOUtil.toHexString(Arrays.copyOfRange(bytes, startingOffset, startingOffset+length)) + "]"; + return "ByteArrayWriter[" + IOUtil.toHexString(Arrays.copyOfRange(bytes, startingOffset, startingOffset + length)) + "]"; } } }