feat(rust): add configurable size guardrails#3579
feat(rust): add configurable size guardrails#3579ayush00git wants to merge 4 commits intoapache:mainfrom
Conversation
|
Hey @chaokunyang |
|
@ayush00git Could you run benchmarks/rust and compare with main branch? |
|
some areas like MediaContentList serialization/deserialization, Sample serialization and StructList deserialization are showing regressions averagely of around 20%, i'll investigate these ones. most probably this is due to field type validations. |
|
StructList and MediaContentList serialize calls still shows around 10% regression feat/rust-sizeguards ## Benchmark Results
### Timing Results (nanoseconds)
| Datatype | Operation | fory (ns) | protobuf (ns) | Fastest |
| ---------------- | ----------- | --------- | ------------- | ------- |
| Struct | Serialize | 68.2 | 122.5 | fory |
| Struct | Deserialize | 37.9 | 64.8 | fory |
| Sample | Serialize | 102.9 | 566.3 | fory |
| Sample | Deserialize | 162.6 | 868.7 | fory |
| MediaContent | Serialize | 219.4 | 332.2 | fory |
| MediaContent | Deserialize | 280.4 | 599.8 | fory |
| StructList | Serialize | 192.0 | 606.2 | fory |
| StructList | Deserialize | 143.2 | 444.3 | fory |
| SampleList | Serialize | 391.3 | 4002.1 | fory |
| SampleList | Deserialize | 1279.0 | 4939.9 | fory |
| MediaContentList | Serialize | 856.0 | 2501.9 | fory |
| MediaContentList | Deserialize | 1676.1 | 3206.9 | fory |
### Throughput Results (ops/sec)
| Datatype | Operation | fory TPS | protobuf TPS | Fastest |
| ---------------- | ----------- | ---------- | ------------ | ------- |
| Struct | Serialize | 14,665,552 | 8,161,267 | fory |
| Struct | Deserialize | 26,369,222 | 15,434,242 | fory |
| Sample | Serialize | 9,721,007 | 1,765,880 | fory |
| Sample | Deserialize | 6,151,575 | 1,151,198 | fory |
| MediaContent | Serialize | 4,558,716 | 3,010,144 | fory |
| MediaContent | Deserialize | 3,565,952 | 1,667,167 | fory |
| StructList | Serialize | 5,208,605 | 1,649,702 | fory |
| StructList | Deserialize | 6,985,191 | 2,250,883 | fory |
| SampleList | Serialize | 2,555,323 | 249,869 | fory |
| SampleList | Deserialize | 781,861 | 202,433 | fory |
| MediaContentList | Serialize | 1,168,170 | 399,696 | fory |
| MediaContentList | Deserialize | 596,623 | 311,828 | fory |
main ## Benchmark Results
### Timing Results (nanoseconds)
| Datatype | Operation | fory (ns) | protobuf (ns) | Fastest |
| ---------------- | ----------- | --------- | ------------- | ------- |
| Struct | Serialize | 67.5 | 123.3 | fory |
| Struct | Deserialize | 38.3 | 63.4 | fory |
| Sample | Serialize | 101.4 | 561.7 | fory |
| Sample | Deserialize | 165.6 | 919.2 | fory |
| MediaContent | Serialize | 213.0 | 332.2 | fory |
| MediaContent | Deserialize | 281.9 | 568.0 | fory |
| StructList | Serialize | 175.2 | 678.8 | fory |
| StructList | Deserialize | 141.8 | 453.0 | fory |
| SampleList | Serialize | 448.6 | 3831.5 | fory |
| SampleList | Deserialize | 1347.9 | 4977.6 | fory |
| MediaContentList | Serialize | 759.1 | 2429.7 | fory |
| MediaContentList | Deserialize | 1665.3 | 3674.4 | fory |
### Throughput Results (ops/sec)
| Datatype | Operation | fory TPS | protobuf TPS | Fastest |
| ---------------- | ----------- | ---------- | ------------ | ------- |
| Struct | Serialize | 14,815,693 | 8,109,642 | fory |
| Struct | Deserialize | 26,132,177 | 15,766,902 | fory |
| Sample | Serialize | 9,864,852 | 1,780,215 | fory |
| Sample | Deserialize | 6,040,471 | 1,087,903 | fory |
| MediaContent | Serialize | 4,695,056 | 3,009,782 | fory |
| MediaContent | Deserialize | 3,547,861 | 1,760,563 | fory |
| StructList | Serialize | 5,707,437 | 1,473,231 | fory |
| StructList | Deserialize | 7,052,684 | 2,207,652 | fory |
| SampleList | Serialize | 2,229,008 | 260,994 | fory |
| SampleList | Deserialize | 741,895 | 200,900 | fory |
| MediaContentList | Serialize | 1,317,402 | 411,573 | fory |
| MediaContentList | Deserialize | 600,492 | 272,153 | fory | |
|
@chaokunyang updated feat/rust-sizeguards bench - Timing Results (nanoseconds)
Throughput Results (ops/sec)
|
|
@chaokunyang |


Why?
To prevent excessive allocation from malicious untrusted payloads in the Rust runtime.
What does this PR do?
This brings the Rust implementation into parity with the C++ runtime by introducing configurable guardrails for binary sizes and collection counts.
Related issues
#3409
AI Contribution Checklist
yes/noyes, I included a completed AI Contribution Checklist in this PR description and the requiredAI Usage Disclosure.yes/noyes, I included the standardizedAI Usage Disclosureblock below.yes, I can explain and defend all important changes without AI help.yes, I reviewed AI-assisted code changes line by line before submission.yes, I completed line-by-line self-review first and fixed issues before requesting AI review.yes, I ran two fresh AI review agents on the current PR diff or current HEAD after the latest code changes: one using.claude/skills/fory-code-review/SKILL.mdand one without that skill.yes, I addressed all AI review comments and repeated the review loop until both ai reviewers reported no further actionable comments.yes, I attached screenshot evidence of the final clean AI review results from both fresh reviewers on the current PR diff or current HEAD after the latest code changes in this PR body.yes, I ran adequate human verification and recorded evidence (checks run locally or in CI, pass/fail summary, and confirmation I reviewed results).yes, I added/updated tests and specs where required.yes, I validated protocol/performance impacts with evidence when applicable.yes, I verified licensing and provenance compliance.AI Usage Disclosure (only when substantial AI assistance =
yes):yes, my PR description includes the requiredai_reviewsummary and screenshot evidence of the final clean AI review results from both fresh reviewers on the current PR diff or current HEAD after the latest code changes.Does this PR introduce any user-facing change?
max_binary_size()andmax_collection_size(), as well asError::SizeLimitExceeded))Benchmark