Skip to content

Commit

Permalink
Merge pull request #40192 from Sanne/BytecodeTransformersCaches
Browse files Browse the repository at this point in the history
Allow Panache bytecode enhancers to benefit from class transformers caches
  • Loading branch information
FroMage authored May 13, 2024
2 parents 9dab695 + dc0c2b5 commit 77cf0a8
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ void replaceFieldAccesses(CombinedIndexBuildItem index,
PanacheJpaEntityAccessorsEnhancer entityAccessorsEnhancer = new PanacheJpaEntityAccessorsEnhancer(index.getIndex(),
modelInfo);
for (String entityClassName : entitiesWithExternallyAccessibleFields) {
transformers.produce(new BytecodeTransformerBuildItem(entityClassName, entityAccessorsEnhancer));
final BytecodeTransformerBuildItem transformation = new BytecodeTransformerBuildItem.Builder()
.setClassToTransform(entityClassName)
.setCacheable(true)
.setVisitorFunction(entityAccessorsEnhancer)
.build();
transformers.produce(transformation);
}

// Replace field access in application code with calls to accessors
Expand All @@ -125,8 +130,17 @@ void replaceFieldAccesses(CombinedIndexBuildItem index,
continue;
}
produced.add(cn);
transformers.produce(
new BytecodeTransformerBuildItem(cn, panacheFieldAccessEnhancer, entityClassNamesInternal));
//The following build item is not marked as CacheAble intentionally: see also https://github.com/quarkusio/quarkus/pull/40192#discussion_r1590605375.
//It shouldn't be too hard to improve on this by checking the related entities haven't been changed
//via LiveReloadBuildItem (#isLiveReload() && #getChangeInformation()) but I'm not comfortable in making this
//change without having solid integration tests.
final BytecodeTransformerBuildItem transformation = new BytecodeTransformerBuildItem.Builder()
.setClassToTransform(cn)
.setCacheable(false)//TODO this would be nice to improve on: see note above.
.setVisitorFunction(panacheFieldAccessEnhancer)
.setRequireConstPoolEntry(entityClassNamesInternal)
.build();
transformers.produce(transformation);
}
}
}
Expand Down

0 comments on commit 77cf0a8

Please sign in to comment.