Skip to content

Commit

Permalink
revert due to performance regression (#1557)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianHuc authored Nov 26, 2024
1 parent e4fea05 commit 89bd38e
Showing 1 changed file with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public final class Bytecode {
/** The bytecode. */
@Getter private final Bytes bytecode;

/** The bytecode hash; precomputed & memoized asynchronously. */
private Future<Hash> hash;
/** The bytecode hash; is null by default and computed & memoized on the fly when required. */
private Hash hash;

/**
* Create an instance from {@link Bytes}.
Expand All @@ -48,7 +48,6 @@ public final class Bytecode {
*/
public Bytecode(Bytes bytes) {
this.bytecode = Objects.requireNonNullElse(bytes, Bytes.EMPTY);
hash = executorService.submit(() -> computeCodeHash());
}

/**
Expand All @@ -58,7 +57,7 @@ public Bytecode(Bytes bytes) {
*/
public Bytecode(Code code) {
this.bytecode = code.getBytes();
this.hash = CompletableFuture.completedFuture(code.getCodeHash());
this.hash = code.getCodeHash();
}

/**
Expand All @@ -85,21 +84,13 @@ public boolean isEmpty() {
* @return the bytecode hash
*/
public Hash getCodeHash() {
try {
return hash.get();
} catch (Exception e) {
log.error("Error while precomputing code hash", e);
Hash computedHash = computeCodeHash();
hash = CompletableFuture.completedFuture(computedHash);
return computedHash;
}
}

private Hash computeCodeHash() {
if (this.bytecode.isEmpty()) {
return Hash.EMPTY;
} else {
return Hash.hash(this.bytecode);
if (this.hash == null) {
if (this.bytecode.isEmpty()) {
this.hash = Hash.EMPTY;
} else {
this.hash = Hash.hash(this.bytecode);
}
}
return this.hash;
}
}

0 comments on commit 89bd38e

Please sign in to comment.