Skip to content

Conversation

buenaflor
Copy link
Contributor

@buenaflor buenaflor commented Aug 6, 2025

💡 Motivation and Context

Performance improvement by avoiding a copy

Benchmarks tested on release mode on Android

I/flutter ( 4261): Envelope Builder Benchmark
I/flutter ( 4261): ==========================
I/flutter ( 4261): Comparing legacy List<int> vs BytesBuilder approaches
I/flutter ( 4261): Envelope size: 1 KB
I/flutter ( 4261): ----------------------------------------
I/flutter ( 4261): Running 1000 iterations...
I/flutter ( 4261): Legacy approach (List<int> + addAll):
I/flutter ( 4261):   Average: 6.2 μs
I/flutter ( 4261):   Min: 5.0 μs
I/flutter ( 4261):   Max: 488.0 μs
I/flutter ( 4261): New approach (BytesBuilder):
I/flutter ( 4261):   Average: 2.1 μs
I/flutter ( 4261):   Min: 2.0 μs
I/flutter ( 4261):   Max: 68.0 μs
I/flutter ( 4261): Performance improvement: 65.7% (2.91x faster)
I/flutter ( 4261): 
I/flutter ( 4261): Envelope size: 10 KB
I/flutter ( 4261): ----------------------------------------
I/flutter ( 4261): Running 1000 iterations...
I/flutter ( 4261): Legacy approach (List<int> + addAll):
I/flutter ( 4261):   Average: 62.3 μs
I/flutter ( 4261):   Min: 54.0 μs
I/flutter ( 4261):   Max: 455.0 μs
I/flutter ( 4261): New approach (BytesBuilder):
I/flutter ( 4261):   Average: 28.6 μs
I/flutter ( 4261):   Min: 27.0 μs
I/flutter ( 4261):   Max: 247.0 μs
I/flutter ( 4261): Performance improvement: 54.1% (2.18x faster)
I/flutter ( 4261): 
I/flutter ( 4261): Envelope size: 100 KB
I/flutter ( 4261): ----------------------------------------
I/flutter ( 4261): Running 500 iterations...
I/flutter ( 4261): Legacy approach (List<int> + addAll):
I/flutter ( 4261):   Average: 1.31 ms
I/flutter ( 4261):   Min: 1.01 ms
I/flutter ( 4261):   Max: 2.88 ms
I/flutter ( 4261): New approach (BytesBuilder):
I/flutter ( 4261):   Average: 287.4 μs
I/flutter ( 4261):   Min: 275.0 μs
I/flutter ( 4261):   Max: 667.0 μs
I/flutter ( 4261): Performance improvement: 78.1% (4.56x faster)
I/flutter ( 4261): 
I/flutter ( 4261): Envelope size: 1 MB
I/flutter ( 4261): ----------------------------------------
I/flutter ( 4261): Running 200 iterations...
I/flutter ( 4261): Legacy approach (List<int> + addAll):
I/flutter ( 4261):   Average: 18.78 ms
I/flutter ( 4261):   Min: 15.30 ms
I/flutter ( 4261):   Max: 22.53 ms
I/flutter ( 4261): New approach (BytesBuilder):
I/flutter ( 4261):   Average: 3.42 ms
I/flutter ( 4261):   Min: 2.76 ms
I/flutter ( 4261):   Max: 5.10 ms
I/flutter ( 4261): Performance improvement: 81.8% (5.50x faster)
I/flutter ( 4261): 
I/flutter ( 4261): Envelope size: 5 MB
I/flutter ( 4261): ----------------------------------------
I/flutter ( 4261): Running 50 iterations...
I/flutter ( 4261): Legacy approach (List<int> + addAll):
I/flutter ( 4261):   Average: 74.45 ms
I/flutter ( 4261):   Min: 68.71 ms
I/flutter ( 4261):   Max: 85.26 ms
I/flutter ( 4261): New approach (BytesBuilder):
I/flutter ( 4261):   Average: 17.92 ms
I/flutter ( 4261):   Min: 15.56 ms
I/flutter ( 4261):   Max: 21.43 ms
I/flutter ( 4261): Performance improvement: 75.9% (4.16x faster)

💚 How did you test it?

Manual + existing tests

📝 Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPii is enabled
  • I updated the docs if needed
  • All tests passing
  • No breaking changes

🔮 Next steps

buenaflor and others added 16 commits August 6, 2025 11:12
* Add melos setup and check only set up Dart for now

* Update

* Update]

* Update]

* Update

* Update

* Update

* Fix CHANGELOG

* Update gitignore

* Fix symlink in CHANGELOG

* Add logging to melos

* Update

* Update

* Update

* Update

* Add dio to packages

* Update workflow

* Update

* Update

* Update

* Update

* Update

* Add hive to packages

* Update
* Add melos setup and check only set up Dart for now

* Update

* Update]

* Update]

* Update

* Update

* Update

* Fix CHANGELOG

* Update gitignore

* Fix symlink in CHANGELOG

* Add logging to melos

* Update

* Update

* Update

* Update

* Add dio to packages

* Update workflow

* Update

* Update

* Update

* Update

* Update

* Add hive to packages

* Update

* Add file to packages

* Update file.yml
* Add melos setup and check only set up Dart for now

* Update

* Update]

* Update]

* Update

* Update

* Update

* Fix CHANGELOG

* Update gitignore

* Fix symlink in CHANGELOG

* Add logging to melos

* Update

* Update

* Update

* Update

* Add dio to packages

* Update workflow

* Update

* Update

* Update

* Update

* Update

* Add hive to packages

* Update

* Add file to packages

* Add link to packages

* Update
* Add melos setup and check only set up Dart for now

* Update

* Update]

* Update]

* Update

* Update

* Update

* Fix CHANGELOG

* Update gitignore

* Fix symlink in CHANGELOG

* Add logging to melos

* Update

* Update

* Update

* Update

* Add dio to packages

* Update workflow

* Update

* Update

* Update

* Update

* Update

* Add hive to packages

* Update

* Add file to packages

* Add link to packages

* Update

* Update

* Update

* Update

* Fix test

* Fix test

* Fix test

* Fix test

* Fix test

* Update drift.yml
* Add melos setup and check only set up Dart for now

* Update

* Update]

* Update]

* Update

* Update

* Update

* Fix CHANGELOG

* Update gitignore

* Fix symlink in CHANGELOG

* Add logging to melos

* Update

* Update

* Update

* Update

* Add dio to packages

* Update workflow

* Update

* Update

* Update

* Update

* Update

* Add hive to packages

* Update

* Add file to packages

* Add link to packages

* Update

* Update

* Update

* Update

* Fix test

* Fix test

* Fix test

* Fix test

* Fix test

* Add flutter to packages

* Update

* Update

* Update

* Update

* Update

* Update

* Update
* Add melos setup and check only set up Dart for now

* Update

* Update]

* Update]

* Update

* Update

* Update

* Fix CHANGELOG

* Update gitignore

* Fix symlink in CHANGELOG

* Add logging to melos

* Update

* Update

* Update

* Update

* Add dio to packages

* Update workflow

* Update

* Update

* Update

* Update

* Update

* Add hive to packages

* Update

* Add file to packages

* Add link to packages

* Update

* Update

* Update

* Update

* Fix test

* Fix test

* Fix test

* Fix test

* Fix test

* Add flutter to packages

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update
* Add melos setup and check only set up Dart for now

* Update

* Update]

* Update]

* Update

* Update

* Update

* Fix CHANGELOG

* Update gitignore

* Fix symlink in CHANGELOG

* Add logging to melos

* Update

* Update

* Update

* Update

* Add dio to packages

* Update workflow

* Update

* Update

* Update

* Update

* Update

* Add hive to packages

* Update

* Add file to packages

* Add link to packages

* Update

* Update

* Update

* Update

* Fix test

* Fix test

* Fix test

* Fix test

* Fix test

* Add flutter to packages

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update
* Add melos setup and check only set up Dart for now

* Update

* Update]

* Update]

* Update

* Update

* Update

* Fix CHANGELOG

* Update gitignore

* Fix symlink in CHANGELOG

* Add logging to melos

* Update

* Update

* Update

* Update

* Add dio to packages

* Update workflow

* Update

* Update

* Update

* Update

* Update

* Add hive to packages

* Update

* Add file to packages

* Add link to packages

* Update

* Update

* Update

* Update

* Fix test

* Fix test

* Fix test

* Fix test

* Fix test

* Add flutter to packages

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update
* Add melos setup and check only set up Dart for now

* Update

* Update]

* Update]

* Update

* Update

* Update

* Fix CHANGELOG

* Update gitignore

* Fix symlink in CHANGELOG

* Add logging to melos

* Update

* Update

* Update

* Update

* Add dio to packages

* Update workflow

* Update

* Update

* Update

* Update

* Update

* Add hive to packages

* Update

* Add file to packages

* Add link to packages

* Update

* Update

* Update

* Update

* Fix test

* Fix test

* Fix test

* Fix test

* Fix test

* Add flutter to packages

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Update

* Clean up

* Updaet

* Updaet

* Update
Copy link

codecov bot commented Aug 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.90%. Comparing base (6b69699) to head (e66fb57).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3147      +/-   ##
==========================================
+ Coverage   87.66%   89.90%   +2.23%     
==========================================
  Files         291       96     -195     
  Lines        9884     3427    -6457     
==========================================
- Hits         8665     3081    -5584     
+ Misses       1219      346     -873     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Base automatically changed from umbrella/melos to main August 6, 2025 13:19
Copy link
Collaborator

@denrase denrase left a comment

Choose a reason for hiding this comment

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

Very nice! Do we need to keep the benchmark test around?

@buenaflor
Copy link
Contributor Author

@denrase I'd just keep it there

@buenaflor buenaflor merged commit 25062b7 into main Aug 6, 2025
55 of 56 checks passed
@buenaflor buenaflor deleted the enh/new-envelope-builder branch August 6, 2025 13:57
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