From 842f672bafd560beeeeebed7accf196101003625 Mon Sep 17 00:00:00 2001 From: Paulo Pinheiro Date: Fri, 4 Oct 2019 00:56:29 +0200 Subject: [PATCH] [FlexBuffers][Java] Cache size of Sized objects in FlexBuffers (#5551) In my benchmarks it shows deserialization performance improvements of around 7% --- java/com/google/flatbuffers/FlexBuffers.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/java/com/google/flatbuffers/FlexBuffers.java b/java/com/google/flatbuffers/FlexBuffers.java index 1cd2227ee..e0eb37b7d 100644 --- a/java/com/google/flatbuffers/FlexBuffers.java +++ b/java/com/google/flatbuffers/FlexBuffers.java @@ -635,12 +635,16 @@ public class FlexBuffers { // Stores size in `byte_width_` bytes before end position. private static abstract class Sized extends Object { + + private final int size; + Sized(ByteBuffer buff, int end, int byteWidth) { super(buff, end, byteWidth); + size = readInt(bb, end - byteWidth, byteWidth); } public int size() { - return readInt(bb, end - byteWidth, byteWidth); + return size; } }