diff options
author | Martin Fick <mfick@nvidia.com> | 2024-12-11 17:26:57 -0800 |
---|---|---|
committer | Martin Fick <mfick@nvidia.com> | 2024-12-13 01:21:44 +0000 |
commit | cdbea5ea96f7e473a48e6bff15e84ecccd521800 (patch) | |
tree | 2dca21436160e6749a9352f20315a03b3f86d650 /org.eclipse.jgit/src | |
parent | ae53d63837857d886cdf15442118597be717ff33 (diff) | |
download | jgit-cdbea5ea96f7e473a48e6bff15e84ecccd521800.tar.gz jgit-cdbea5ea96f7e473a48e6bff15e84ecccd521800.zip |
Optionally.Hard: avoid Optional creation on every use,
Previously the getOptional() call created an new Optional for its
element, and this appears to be somewhat expensive. During a time when a
server is heavily loaded because of a poorly maintained repository with
potentially 2K+ pack files, calls to Optionally.ofNullable() from within
the getOptional() method appeared extensively in the Stacktrace. Reduce
the getOptional() call overhead by storing an already created Optional
of the element instead of the element itself. This trades the extra
space of one extra reference for a potential speed gain in a hotspot.
Since the current users of Optionally.Hard reference objects
significantly larger than a single reference (and most users are likely
to be, else why would they be using an Optionally?), this is likely a
good tradeoff.
Change-Id: I7adccc915480cbb97a43dcbe074cfb620888c936
Signed-off-by: Martin Fick <mfick@nvidia.com>
Diffstat (limited to 'org.eclipse.jgit/src')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/internal/util/Optionally.java | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/util/Optionally.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/util/Optionally.java index 3447f669ab..270b760562 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/util/Optionally.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/util/Optionally.java @@ -53,24 +53,24 @@ public interface Optionally<T> { /** * The mutable optional object */ - protected T element; + protected Optional<T> optional; /** * @param element * the mutable optional object */ public Hard(T element) { - this.element = element; + optional = Optional.ofNullable(element); } @Override public void clear() { - element = null; + optional = Optional.empty(); } @Override public Optional<T> getOptional() { - return Optional.ofNullable(element); + return optional; } } |