From 902594715659345cb85e92855506e6dabba6724d Mon Sep 17 00:00:00 2001 From: Shawn Yang Date: Tue, 24 Sep 2024 01:06:13 -0700 Subject: [PATCH] perf(java): inline same element invoke in jit (#1851) ## What does this PR do? ## Related issues ## Does this PR introduce any user-facing change? - [ ] Does this PR introduce any public API change? - [ ] Does this PR introduce any binary protocol compatibility change? ## Benchmark --- .../fury/builder/BaseObjectCodecBuilder.java | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java b/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java index e58098bb5d..b1b43d3651 100644 --- a/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java +++ b/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java @@ -1278,18 +1278,16 @@ protected Expression readCollectionCodegen( readBuilder.add( readContainerElements( elementType, true, elemSerializer, null, buffer, collection, size)); - Set cutPoint = ofHashSet(buffer, collection, size); - if (maybeDecl) { // For `isDeclType` - cutPoint.add(flags); - } - Expression sameElementClassRead = - invokeGenerated(ctx, cutPoint, readBuilder, "sameElementClassRead", false); // Same element class read end - action = - new If( - sameElementClass, - sameElementClassRead, - readContainerElements(elementType, true, null, null, buffer, collection, size)); + Set cutPoint = ofHashSet(buffer, collection, size); + Expression differentElemTypeRead = + invokeGenerated( + ctx, + cutPoint, + readContainerElements(elementType, true, null, null, buffer, collection, size), + "differentTypeElemsRead", + false); + action = new If(sameElementClass, readBuilder, differentElemTypeRead); } else { Literal hasNullFlag = Literal.ofInt(CollectionFlags.HAS_NULL); Expression hasNull = eq(new BitAnd(flags, hasNullFlag), hasNullFlag, "hasNull"); @@ -1299,18 +1297,16 @@ protected Expression readCollectionCodegen( readBuilder.add( readContainerElements( elementType, false, elemSerializer, hasNull, buffer, collection, size)); - Set cutPoint = ofHashSet(buffer, collection, size, hasNull); - if (maybeDecl) { // For `isDeclType` - cutPoint.add(flags); - } // Same element class read end - Expression sameElementClassRead = - invokeGenerated(ctx, cutPoint, readBuilder, "sameElementClassRead", false); - action = - new If( - sameElementClass, - sameElementClassRead, - readContainerElements(elementType, false, null, hasNull, buffer, collection, size)); + Set cutPoint = ofHashSet(buffer, collection, size, hasNull); + Expression differentTypeElemsRead = + invokeGenerated( + ctx, + cutPoint, + readContainerElements(elementType, false, null, hasNull, buffer, collection, size), + "differentTypeElemsRead", + false); + action = new If(sameElementClass, readBuilder, differentTypeElemsRead); } builder.add(action); }