[api] Emit raw tag+value writes for force=true fixed32 fields

Instead of ALWAYS_INLINE on encode_field_raw (which bloated all
callers), have the code generator precompute the tag byte and emit
write_raw_byte(tag) + write_fixed32_raw(value) directly.

This gives the same tight codegen (single byte store + memcpy) for
key fields without inflating encode_bool/encode_uint32/etc.

+108 bytes flash vs baseline, -48 bytes vs the ALWAYS_INLINE approach.
This commit is contained in:
J. Nick Koston
2026-03-20 23:28:19 -10:00
parent 7ce24edabb
commit 21725983fd
3 changed files with 121 additions and 51 deletions
+13
View File
@@ -556,6 +556,19 @@ class Fixed32Type(TypeInfo):
o += "out.append(buffer);"
return o
@property
def encode_content(self) -> str:
tag = (self.number << 3) | (self.wire_type & 0b111)
if self.force and tag < 128:
# Emit raw byte writes: precomputed tag + direct memcpy
return (
f"buffer.write_raw_byte({tag});\n"
f"buffer.write_fixed32_raw(this->{self.field_name});"
)
if self.force:
return f"buffer.{self.encode_func}({self.number}, this->{self.field_name}, true);"
return f"buffer.{self.encode_func}({self.number}, this->{self.field_name});"
def get_size_calculation(self, name: str, force: bool = False) -> str:
field_id_size = self.calculate_field_id_size()
if force: