Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(java): jit support for chunk based map serialization #2027

Merged
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b9e4bf6
jit write for chunk based map serialization
chaokunyang Jan 26, 2025
6f4435e
add variable decl expr
chaokunyang Jan 27, 2025
d317e4d
fix inline expr
chaokunyang Jan 27, 2025
30067ce
finish chunk writing codegen
chaokunyang Jan 27, 2025
301cbdf
fix TRACKING_KEY_REF flag
chaokunyang Jan 27, 2025
753e0ec
add more expressions
chaokunyang Jan 27, 2025
cfc6dd5
support jit for chunk read
chaokunyang Jan 27, 2025
db711a3
fix read jit
chaokunyang Jan 27, 2025
8d8ec2d
fix non-final map kv type jit
chaokunyang Jan 27, 2025
261b3d6
remove null from read kv serializer
chaokunyang Jan 27, 2025
977970a
support ref tracking for map chunk encoding
chaokunyang Jan 27, 2025
caf1dde
support nested map chunk encoding
chaokunyang Jan 27, 2025
ca1483d
remove old map serialization protocol
chaokunyang Jan 27, 2025
ca83c32
fix buffer rewind
chaokunyang Jan 27, 2025
8c10258
fix nested map class info reading
chaokunyang Jan 27, 2025
21e55ac
inline recursive by expr inputs
chaokunyang Jan 28, 2025
bde5b7d
inline chunk write/read and fix generics push/pop
chaokunyang Jan 28, 2025
df0be05
optimize inline invoke
chaokunyang Jan 28, 2025
9d763e0
lint code
chaokunyang Jan 28, 2025
7b090f9
fix get collection serializer
chaokunyang Jan 28, 2025
480446f
fix cast expr empty code
chaokunyang Jan 28, 2025
6f22c80
fix pkg level accessible
chaokunyang Jan 28, 2025
0b4a9c7
remove chunk switch
chaokunyang Jan 28, 2025
88d4a9c
refactor MapSerializationSuite
chaokunyang Jan 28, 2025
75e7e4b
extract readElements for scala map serializer
chaokunyang Jan 28, 2025
702e661
fix InvokeHint conflict
chaokunyang Jan 28, 2025
4305851
fix read chunk inline
chaokunyang Jan 28, 2025
a029cb1
fast path for read/write null k/v chunk
chaokunyang Jan 28, 2025
1ebeddb
add map benchmark plot script
chaokunyang Jan 28, 2025
96b53f8
fix wrong path in plot script
chaokunyang Jan 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 160 additions & 0 deletions java/benchmark/plot_map_benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

# Load the CSV data
no_chunk_file = (
"/Users/chaokunyang/Desktop/chaokun/fury_open_source/nochunk-jmh-result.csv"
chaokunyang marked this conversation as resolved.
Show resolved Hide resolved
)
chunk_file = "/Users/chaokunyang/Desktop/chaokun/fury_open_source/chunk-jmh-result.csv"
# Read the CSV files
no_chunk_df = pd.read_csv(no_chunk_file)
chunk_df = pd.read_csv(chunk_file)


# Function to plot the figures
def plot_benchmark(ax, data1, data2, operation, struct, datatype, title):
# Filter data
filtered_data1 = data1[
(data1["Benchmark"] == (operation))
& (data1["struct"] == struct)
& (data1["datatype"] == datatype)
]
filtered_data2 = data2[
(data2["Benchmark"] == (operation))
& (data2["struct"] == struct)
& (data2["datatype"] == datatype)
]

# Sort data according to 'mapSize'
filtered_data1 = filtered_data1.sort_values("mapSize")
filtered_data2 = filtered_data2.sort_values("mapSize")

# Plotting
x_labels = filtered_data1["mapSize"].astype(str).tolist()
x = np.arange(len(x_labels))
width = 0.35

ax.bar(
x - width / 2,
filtered_data1["Score"],
width,
yerr=filtered_data1["ScoreError"],
label="No Chunk",
)
ax.bar(
x + width / 2,
filtered_data2["Score"],
width,
yerr=filtered_data2["ScoreError"],
label="Chunk",
)
ax.set_xlabel("Map Size")
ax.set_ylabel("Score (ops/s)")
ax.set_title(title)
ax.set_xticks(x)
ax.set_xticklabels(x_labels)
ax.legend()


# Create the subplots for datatype "int"
fig1, axs1 = plt.subplots(2, 2, figsize=(10, 8))
plot_benchmark(
axs1[0, 0],
no_chunk_df,
chunk_df,
"serialize",
True,
"int",
"Serialize | Datatype: Int",
)
plot_benchmark(
axs1[0, 1],
no_chunk_df,
chunk_df,
"serialize",
True,
"string",
"Serialize | Datatype: String",
)
plot_benchmark(
axs1[1, 0],
no_chunk_df,
chunk_df,
"deserialize",
True,
"int",
"Deserialize | Datatype: Int",
)
plot_benchmark(
axs1[1, 1],
no_chunk_df,
chunk_df,
"deserialize",
True,
"string",
"Deserialize | Datatype: String",
)
plt.tight_layout()
plt.suptitle("Benchmarks for codegen", y=1.05)


# Create the subplots for datatype "string"
fig2, axs2 = plt.subplots(2, 2, figsize=(10, 8))
plot_benchmark(
axs2[0, 0],
no_chunk_df,
chunk_df,
"serialize",
False,
"int",
"Serialize | Datatype: Int",
)
plot_benchmark(
axs2[0, 1],
no_chunk_df,
chunk_df,
"serialize",
False,
"string",
"Serialize | Datatype: String",
)
plot_benchmark(
axs2[1, 0],
no_chunk_df,
chunk_df,
"deserialize",
False,
"int",
"Deserialize | Datatype: Int",
)
plot_benchmark(
axs2[1, 1],
no_chunk_df,
chunk_df,
"deserialize",
False,
"string",
"Deserialize | Datatype: String",
)
plt.tight_layout()
plt.suptitle("Benchmarks for no codegen", y=1.05)

plt.show()
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import java.util.HashMap;
import java.util.Map;
import org.apache.fury.Fury;
import org.apache.fury.serializer.Serializer;
import org.apache.fury.serializer.collection.AbstractMapSerializer;
import org.openjdk.jmh.Main;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
Expand All @@ -49,53 +47,70 @@ public static void main(String[] args) throws IOException {
Main.main(args);
}

public static class StringKVMapStruct {
Map<String, String> map;
}

public static class IntKVMapStruct {
Map<Integer, Integer> map;
}

@State(Scope.Thread)
public static class MapState {
@Param({"5", "20", "50", "100", "200"})
@Param({"50"})
public int mapSize;

@Param({"false", "true"})
public boolean enableChunkEncoding;
public boolean struct;

@Param({"int", "string"})
public String datatype;

private Map<String, String> stringMap;
private Map<Integer, Integer> integerMap;
private byte[] stringMapBytes;
private byte[] integerMapBytes;
private Object object;
private byte[] bytes;
private Fury fury;

@Setup(Level.Trial)
public void setup() {
fury = Fury.builder().build();
Serializer<HashMap> serializer = fury.getSerializer(HashMap.class);
((AbstractMapSerializer) serializer).setUseChunkSerialize(enableChunkEncoding);
stringMap = new HashMap<>(mapSize);
integerMap = new HashMap<>(mapSize);
fury.register(StringKVMapStruct.class);
fury.register(IntKVMapStruct.class);
Map<String, String> stringMap = new HashMap<>(mapSize);
Map<Integer, Integer> intMap = new HashMap<>(mapSize);
for (int i = 0; i < mapSize; i++) {
stringMap.put("k" + i, "v" + i);
integerMap.put(i, i * 2);
intMap.put(i, i * 2);
}
StringKVMapStruct stringKVMapStruct = new StringKVMapStruct();
stringKVMapStruct.map = stringMap;
IntKVMapStruct intKVMapStruct = new IntKVMapStruct();
intKVMapStruct.map = intMap;
byte[] stringMapBytes = fury.serialize(stringMap);
byte[] intMapBytes = fury.serialize(intMap);
byte[] stringKVStructBytes = fury.serialize(stringKVMapStruct);
byte[] intKVStructBytes = fury.serialize(intKVMapStruct);
switch (datatype) {
case "int":
object = struct ? intKVMapStruct : intMap;
bytes = struct ? intKVStructBytes : intMapBytes;
break;
case "string":
object = struct ? stringKVMapStruct : stringMap;
bytes = struct ? stringKVStructBytes : stringMapBytes;
break;
default:
throw new UnsupportedOperationException();
}
stringMapBytes = fury.serialize(stringMap);
integerMapBytes = fury.serialize(integerMap);
}
}

@Benchmark
public Object serializeStringMap(MapState state) {
return state.fury.serialize(state.stringMap);
}

@Benchmark
public Object serializeIntMap(MapState state) {
return state.fury.serialize(state.integerMap);
}

@Benchmark
public Object deserializeStringMap(MapState state) {
return state.fury.deserialize(state.stringMapBytes);
public Object serialize(MapState state) {
return state.fury.serialize(state.object);
}

@Benchmark
public Object deserializeIntMap(MapState state) {
return state.fury.deserialize(state.integerMapBytes);
public Object deserialize(MapState state) {
return state.fury.deserialize(state.bytes);
}
}
Loading
Loading