Skip to content

feat(codegen): generate Clean methods and allow for object pooling - #24

Open
mircodz wants to merge 8 commits into
mainfrom
clear
Open

mircodz wants to merge 8 commits into
mainfrom
clear

Conversation

@mircodz

@mircodz mircodz commented Oct 7, 2026

Copy link
Copy Markdown
Owner

No description provided.

`--clear` (MSBuild: `BondClear`) generates Clear(), which resets every field
to the default the constructor gives it. Collections are emptied and structs
from the same file are cleared in place, so a cleared instance keeps its
storage for the next read; structs from other files are replaced.
Deserialize(data, into), for spans, sequences and streams, reads into the
given instance as Bond merges: the payload's fields replace the instance's,
nested structs are read into its own and container elements are appended.
After Clear(), the instance reads as a new one would, keeping its storage.
Each read also runs as Clear() followed by Deserialize(bytes, into), in the same category, so reuse shows next to a new instance.
The README's read table gets a column for reads into a reused instance.
The runtime README links to them, and benchmarks/RESULTS.md becomes benchmarks/README.md, which GitHub shows with the folder. The i7 numbers are rerun, pinned away from a busy core.
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Code Coverage Report

Line Coverage: 80.8%
Branch Coverage: 84.3%

View detailed coverage
Summary
  Generated on: 10/10/2026 - 20:41:22
  Coverage date: 10/10/2026 - 20:40:56 - 10/10/2026 - 20:41:20
  Parser: MultiReport (2x Cobertura)
  Assemblies: 1
  Classes: 7
  Files: 6
  Line coverage: 80.8%
  Covered lines: 491
  Uncovered lines: 116
  Coverable lines: 607
  Total lines: 1466
  Branch coverage: 84.3% (194 of 230)
  Covered branches: 194
  Total branches: 230
  Method coverage: 65.5% (143 of 218)
  Covered methods: 143
  Total methods: 218
  Tag: 88_38084609535

BondTools.Runtime                         80.8%
  BondTools.Runtime.BondCodec             42.2%
  BondTools.Runtime.BondCodec<T>           0.0%
  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 8acdccf

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Generic nested values bypass reuse, and the new abstract interface members break existing implementations.

5 open findings
What changed in this PR

Adds generated model clearing and deserialize-into APIs to support instance reuse and object pooling.

Changes:

  • Adds optional Clear() generation through CLI and MSBuild.
  • Adds runtime and generated deserialization-into-existing-instance APIs.
  • Expands tests, benchmarks, documentation, dependencies, and package versioning.
File Description
version Bumps version to 1.7.0.
tests/​Bond.Parser.Tests/​CSharpSerializationTests.cs Tests deserialize-into overloads.
tests/​Bond.Parser.Tests/​CSharpModelFeatureTests.cs Tests generated clearing behavior.
tests/​Bond.Build.Tests/​MsBuildGenerationTests.cs Tests MSBuild clear generation.
README.md Documents CLI usage and performance.
Directory.Packages.props Updates dependencies.
Bond.Runtime/​README.md Documents instance reuse.
Bond.Runtime/​IBondStruct.cs Extends the serialization interface.
Bond.Runtime/​CompactBinary.cs Adds deserialize-into overloads.
Bond.Runtime/​BondCodec.cs Adds into-aware codec reading.
Bond.Parser/​CodeGeneration/​CSharpSerializationEmitter.cs Generates deserialize-into APIs.
Bond.Parser/​CodeGeneration/​CSharpModelEmitter.cs Generates Clear() implementations.
Bond.Parser/​CodeGeneration/​CSharpGenerationOptions.cs Adds the clearing feature flag.
Bond.Parser.CLI/​Program.cs Adds --clear.
Bond.Build/​README.md Documents BondClear.
Bond.Build/​GenerateBond.cs Reads clear-generation metadata.
Bond.Build/​build/​BondTools.Build.targets Forwards BondClear.
benchmarks/​RESULTS.md Removes the former results file.
benchmarks/​README.md Adds updated benchmark results.
benchmarks/​Benchmarks.csproj Enables clearing in benchmark codegen.
benchmarks/​Benchmarks.cs Benchmarks reused deserialization.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread Bond.Runtime/IBondStruct.cs
Comment on lines +135 to +139
Line(3, $"public override {self} Read(ref {Runtime}CompactBinaryReader reader, {Runtime}WireType type, {self} into)");
Line(3, "{");
Line(4, $"{Runtime}CompactBinaryReader.Expect(type, {Runtime}WireType.Struct);");
Line(4, $"return {self}.Read(ref reader, into{_codecArguments});");
Line(3, "}");
Comment thread Bond.Runtime/CompactBinary.cs Outdated
Comment thread Bond.Runtime/CompactBinary.cs
Comment thread Bond.Runtime/README.md

## Reusing instances

`Deserialize(bytes, into)` reads into an existing instance, as Bond merges: the payload's fields replace the instance's, nested structs are read into the instance's own, and container elements are appended. With `--clear`, clearing first reads it as a new instance would, while keeping its lists and nested structs, so only strings and new elements are allocated:
mircodz and others added 2 commits October 10, 2026 22:39
Add null checks for input, into, and codec parameters.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Added null checks for 'into' and 'codec' parameters in Deserialize method.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

2 participants