Skip to content

perf(runtime): better varint and string serde - #23

Merged
mircodz merged 4 commits into
mainfrom
perf-varints
Oct 2, 2026
Merged

mircodz merged 4 commits into
mainfrom
perf-varints

Conversation

@mircodz

@mircodz mircodz commented Oct 2, 2026

Copy link
Copy Markdown
Owner

No description provided.

Varints of one or two bytes (values below 2^14) are read and written inline,
with one bounds check for both bytes. Longer ones go out of line, through pdep
and pext where BMI2 is fast: everywhere but AMD families 15h to 18h. Reads
still consume the same bytes and return the same values as upstream's.
ASCII strings, the common case, are written in one narrowing pass, since
their byte count is their length, and read by widening, which Latin-1 does
for ASCII exactly as UTF-8 does. Other strings up to 5,461 characters are
encoded in one pass too, after room for the longest length prefix they can
need. The bytes written and the strings read are unchanged.
Buffer growth and the exceptions for malformed payloads were inlined into
every generated read and write method. Out of line, the generated code is
15% smaller, and writers 25%.
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Code Coverage Report

Line Coverage: 89.7%
Branch Coverage: 83.9%

View detailed coverage
Summary
  Generated on: 10/02/2026 - 14:32:39
  Coverage date: 10/02/2026 - 14:32:20 - 10/02/2026 - 14:32:37
  Parser: MultiReport (2x Cobertura)
  Assemblies: 2
  Classes: 69
  Files: 56
  Line coverage: 89.7%
  Covered lines: 4227
  Uncovered lines: 484
  Coverable lines: 4711
  Total lines: 10080
  Branch coverage: 83.9% (3230 of 3849)
  Covered branches: 3230
  Total branches: 3849
  Method coverage: 82% (557 of 679)
  Covered methods: 557
  Total methods: 679
  Tag: 84_37020470836

Bond.Parser                                            91.0%
  Bond.Parser.CodeGeneration.CSharpGenerationOptions  100.0%
  Bond.Parser.CodeGeneration.CSharpGenerationResult   100.0%
  Bond.Parser.CodeGeneration.CSharpGenerator           94.3%
  Bond.Parser.Compatibility.CompatibilityChecker       95.2%
  Bond.Parser.Compatibility.CompatibilityOptions      100.0%
  Bond.Parser.Compatibility.CompatibilityResult       100.0%
  Bond.Parser.Compatibility.ContractDeclaration       100.0%
  Bond.Parser.Compatibility.ContractField             100.0%
  Bond.Parser.Compatibility.DiagnosticIds             100.0%
  Bond.Parser.Compatibility.SchemaChange               36.8%
  Bond.Parser.Compatibility.SchemaContract            100.0%
  Bond.Parser.Compatibility.SchemaContractBuilder      96.1%
  Bond.Parser.Compatibility.SchemaContractValidation   97.8%
  Bond.Parser.Compatibility.TypeShape                 100.0%
  Bond.Parser.Formatting.BondFormatter                 82.2%
  Bond.Parser.Formatting.FormatResult                 100.0%
  Bond.Parser.Json.AttributeJsonConverter             100.0%
  Bond.Parser.Json.BondJsonConverter                  100.0%
  Bond.Parser.Json.BondJsonSerializerOptions           82.3%
  Bond.Parser.Json.BondTypeJsonConverter               97.9%
  Bond.Parser.Json.ConstantJsonConverter              100.0%
  Bond.Parser.Json.DeclarationJsonConverter            95.8%
  Bond.Parser.Json.DefaultJsonConverter                95.6%
  Bond.Parser.Json.FieldJsonConverter                  95.6%
  Bond.Parser.Json.ImportJsonConverter                100.0%
  Bond.Parser.Json.MethodJsonConverter                 96.7%
  Bond.Parser.Json.MethodTypeJsonConverter             85.7%
  Bond.Parser.Json.NamespaceJsonConverter              75.0%
  Bond.Parser.Json.TypeParamJsonConverter             100.0%
  Bond.Parser.Json.WriteOnlyJsonConverter<T>            0.0%
  Bond.Parser.Parser.AstBuilder                        95.5%
  Bond.Parser.Parser.DefaultImportResolver            100.0%
  Bond.Parser.Parser.ErrorListener                    100.0%
  Bond.Parser.Parser.ParseError                       100.0%
  Bond.Parser.Parser.ParseErrorsException             100.0%
  Bond.Parser.Parser.ParseResult                      100.0%
  Bond.Parser.Parser.ParserFacade                      86.0%
  Bond.Parser.Parser.SemanticAnalyzer                  91.3%
  Bond.Parser.Parser.SemanticErrorException           100.0%
  Bond.Parser.Parser.SymbolTable                       86.6%
  Bond.Parser.Parser.TypeResolver                      84.9%
  Bond.Parser.Parser.TypeValidator                     92.0%
  Bond.Parser.Syntax.AliasDeclaration                   0.0%
  Bond.Parser.Syntax.Attribute                         80.0%
  Bond.Parser.Syntax.Bond                              83.3%
  Bond.Parser.Syntax.BondType                          68.6%
  Bond.Parser.Syntax.BondTypeExtensions                93.7%
  Bond.Parser.Syntax.Constant                          80.0%
  Bond.Parser.Syntax.Declaration                      100.0%
  Bond.Parser.Syntax.Default                           33.3%
  Bond.Parser.Syntax.EnumDeclaration                    0.0%
  Bond.Parser.Syntax.EventMethod                        0.0%
  Bond.Parser.Syntax.Field                             50.0%
  Bond.Parser.Syntax.ForwardDeclaration                25.0%
  Bond.Parser.Syntax.FunctionMethod                     0.0%
  Bond.Parser.Syntax.Import                             0.0%
  Bond.Parser.Syntax.MethodType                        50.0%
  Bond.Parser.Syntax.Namespace                         66.6%
  Bond.Parser.Syntax.ServiceDeclaration                 0.0%
  Bond.Parser.Syntax.SourceLocation                     0.0%
  Bond.Parser.Syntax.StructDeclaration                 16.6%
  Bond.Parser.Syntax.TypeParam                         80.0%
  Bond.Parser.Util.Extensions                         100.0%

BondTools.Runtime                                      80.4%
  BondTools.Runtime.BondCodec                          41.6%
  BondTools.Runtime.BondedPayload<T>                   90.0%
  BondTools.Runtime.CompactBinary                     100.0%
  BondTools.Runtime.CompactBinaryReader                95.7%
  BondTools.Runtime.CompactBinaryWriter                98.5%
  BondTools.Runtime.FastPdep                          100.0%

Coverage report generated for commit c5768dc

Single launches varied by up to 15% from one process to the next. The
README and RESULTS.md are refreshed with the varint, string and rare-path
changes.
@mircodz
mircodz merged commit 779470c into main Oct 2, 2026
2 checks passed
@mircodz
mircodz deleted the perf-varints branch October 2, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant