Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ jobs:
python:
name: Python CI
needs: changes
if: needs.changes.outputs.python == 'true'
if: needs.changes.outputs.python == 'true' || needs.changes.outputs.cpp == 'true'
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand Down Expand Up @@ -1039,7 +1039,7 @@ jobs:
python_windows:
name: Python CI (${{ matrix.python-version }}, windows-2022)
needs: changes
if: needs.changes.outputs.python == 'true'
if: needs.changes.outputs.python == 'true' || needs.changes.outputs.cpp == 'true'
runs-on: windows-2022
strategy:
matrix:
Expand Down
58 changes: 25 additions & 33 deletions benchmarks/cpp/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ struct NumericStruct {
}
MSGPACK_DEFINE_MAP(f1, f2, f3, f4, f5, f6, f7, f8);
};
FORY_STRUCT(NumericStruct, f1, f2, f3, f4, f5, f6, f7, f8);
FORY_FIELD_TAGS(NumericStruct, (f1, 1), (f2, 2), (f3, 3), (f4, 4), (f5, 5),
(f6, 6), (f7, 7), (f8, 8));
FORY_STRUCT(NumericStruct, (f1, fory::F(1)), (f2, fory::F(2)), (f3, fory::F(3)),
(f4, fory::F(4)), (f5, fory::F(5)), (f6, fory::F(6)),
(f7, fory::F(7)), (f8, fory::F(8)));

struct Sample {
int32_t int_value;
Expand Down Expand Up @@ -103,20 +103,17 @@ struct Sample {
int_array, long_array, float_array, double_array,
short_array, char_array, boolean_array, string);
};
FORY_STRUCT(Sample, int_value, long_value, float_value, double_value,
short_value, char_value, boolean_value, int_value_boxed,
long_value_boxed, float_value_boxed, double_value_boxed,
short_value_boxed, char_value_boxed, boolean_value_boxed, int_array,
long_array, float_array, double_array, short_array, char_array,
boolean_array, string);
FORY_FIELD_TAGS(Sample, (int_value, 1), (long_value, 2), (float_value, 3),
(double_value, 4), (short_value, 5), (char_value, 6),
(boolean_value, 7), (int_value_boxed, 8), (long_value_boxed, 9),
(float_value_boxed, 10), (double_value_boxed, 11),
(short_value_boxed, 12), (char_value_boxed, 13),
(boolean_value_boxed, 14), (int_array, 15), (long_array, 16),
(float_array, 17), (double_array, 18), (short_array, 19),
(char_array, 20), (boolean_array, 21), (string, 22));
FORY_STRUCT(Sample, (int_value, fory::F(1)), (long_value, fory::F(2)),
(float_value, fory::F(3)), (double_value, fory::F(4)),
(short_value, fory::F(5)), (char_value, fory::F(6)),
(boolean_value, fory::F(7)), (int_value_boxed, fory::F(8)),
(long_value_boxed, fory::F(9)), (float_value_boxed, fory::F(10)),
(double_value_boxed, fory::F(11)), (short_value_boxed, fory::F(12)),
(char_value_boxed, fory::F(13)), (boolean_value_boxed, fory::F(14)),
(int_array, fory::F(15)), (long_array, fory::F(16)),
(float_array, fory::F(17)), (double_array, fory::F(18)),
(short_array, fory::F(19)), (char_array, fory::F(20)),
(boolean_array, fory::F(21)), (string, fory::F(22)));

// Enums for MediaContent benchmark
enum class Player : int32_t { JAVA = 0, FLASH = 1 };
Expand Down Expand Up @@ -150,11 +147,11 @@ struct Media {
MSGPACK_DEFINE_MAP(uri, title, width, height, format, duration, size, bitrate,
has_bitrate, persons, player, copyright);
};
FORY_STRUCT(Media, uri, title, width, height, format, duration, size, bitrate,
has_bitrate, persons, player, copyright);
FORY_FIELD_TAGS(Media, (uri, 1), (title, 2), (width, 3), (height, 4),
(format, 5), (duration, 6), (size, 7), (bitrate, 8),
(has_bitrate, 9), (persons, 10), (player, 11), (copyright, 12));
FORY_STRUCT(Media, (uri, fory::F(1)), (title, fory::F(2)), (width, fory::F(3)),
(height, fory::F(4)), (format, fory::F(5)), (duration, fory::F(6)),
(size, fory::F(7)), (bitrate, fory::F(8)),
(has_bitrate, fory::F(9)), (persons, fory::F(10)),
(player, fory::F(11)), (copyright, fory::F(12)));

struct Image {
std::string uri;
Expand All @@ -169,9 +166,8 @@ struct Image {
}
MSGPACK_DEFINE_MAP(uri, title, width, height, size);
};
FORY_STRUCT(Image, uri, title, width, height, size);
FORY_FIELD_TAGS(Image, (uri, 1), (title, 2), (width, 3), (height, 4),
(size, 5));
FORY_STRUCT(Image, (uri, fory::F(1)), (title, fory::F(2)), (width, fory::F(3)),
(height, fory::F(4)), (size, fory::F(5)));

struct MediaContent {
Media media;
Expand All @@ -182,8 +178,7 @@ struct MediaContent {
}
MSGPACK_DEFINE_MAP(media, images);
};
FORY_STRUCT(MediaContent, media, images);
FORY_FIELD_TAGS(MediaContent, (media, 1), (images, 2));
FORY_STRUCT(MediaContent, (media, fory::F(1)), (images, fory::F(2)));

struct StructList {
std::vector<NumericStruct> struct_list;
Expand All @@ -193,8 +188,7 @@ struct StructList {
}
MSGPACK_DEFINE_MAP(struct_list);
};
FORY_STRUCT(StructList, struct_list);
FORY_FIELD_TAGS(StructList, (struct_list, 1));
FORY_STRUCT(StructList, (struct_list, fory::F(1)));

struct SampleList {
std::vector<Sample> sample_list;
Expand All @@ -204,8 +198,7 @@ struct SampleList {
}
MSGPACK_DEFINE_MAP(sample_list);
};
FORY_STRUCT(SampleList, sample_list);
FORY_FIELD_TAGS(SampleList, (sample_list, 1));
FORY_STRUCT(SampleList, (sample_list, fory::F(1)));

struct MediaContentList {
std::vector<MediaContent> media_content_list;
Expand All @@ -215,8 +208,7 @@ struct MediaContentList {
}
MSGPACK_DEFINE_MAP(media_content_list);
};
FORY_STRUCT(MediaContentList, media_content_list);
FORY_FIELD_TAGS(MediaContentList, (media_content_list, 1));
FORY_STRUCT(MediaContentList, (media_content_list, fory::F(1)));

// ============================================================================
// Test data creation
Expand Down
30 changes: 28 additions & 2 deletions benchmarks/cpp/benchmark_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@
"protobuf": "protobuf",
"msgpack": "msgpack",
}
DATATYPE_ORDER = [
"struct",
"sample",
"mediacontent",
"structlist",
"samplelist",
"mediacontentlist",
]
DATATYPE_ORDER_INDEX = {
datatype: index for index, datatype in enumerate(DATATYPE_ORDER)
}

# === Parse arguments ===
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -135,6 +146,16 @@ def format_datatype_table_label(datatype):
return datatype.capitalize()


def ordered_datatypes(datatypes):
return sorted(
datatypes,
key=lambda datatype: (
DATATYPE_ORDER_INDEX.get(datatype, len(DATATYPE_ORDER)),
datatype,
),
)


# === Read and parse benchmark JSON ===
def load_benchmark_data(json_file):
with open(json_file, "r", encoding="utf-8") as f:
Expand Down Expand Up @@ -243,7 +264,7 @@ def plot_datatype(ax, datatype, operation):

# === Create plots ===
plot_images = []
datatypes = sorted(data.keys())
datatypes = ordered_datatypes(data.keys())
operations = ["serialize", "deserialize"]

for datatype in datatypes:
Expand Down Expand Up @@ -343,7 +364,12 @@ def plot_combined_tps_subplot(ax, grouped_datatypes, operation, title):
md_report.append("\n## Benchmark Plots\n")
md_report.append("\nAll class-level plots below show throughput (ops/sec).\n")
plot_images_sorted = sorted(
plot_images, key=lambda item: (0 if item[0] == "throughput" else 1, item[0])
plot_images,
key=lambda item: (
0 if item[0] == "throughput" else 1,
DATATYPE_ORDER_INDEX.get(item[0], len(DATATYPE_ORDER)),
item[0],
),
)
for datatype, img in plot_images_sorted:
img_filename = os.path.basename(img)
Expand Down
5 changes: 4 additions & 1 deletion compiler/fory_compiler/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,10 @@ def compile_file(
print("======================")

# Validate merged schema
validator = SchemaValidator(schema)
allow_nested_collections = set(lang_output_dirs) == {"cpp"}
validator = SchemaValidator(
schema, allow_nested_collections=allow_nested_collections
)
if not validator.validate():
for error in validator.errors:
print(f"Error: {error}", file=sys.stderr)
Expand Down
1 change: 1 addition & 0 deletions compiler/fory_compiler/frontend/proto/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ def _translate_oneof_field_reference(
oneof_type_name, location=self._location(oneof.line, oneof.column)
),
number=first_case.number,
tag_id=first_case.number,
optional=True,
ref=False,
options={},
Expand Down
Loading
Loading