Skip to content

Conversation

kevmoo
Copy link
Contributor

@kevmoo kevmoo commented Jun 22, 2024

Status

READY

Description

Use Expando instead of cloning each request.

  • Should improve performance. Should be measured.
  • Allows nested _request to be final. (Potentially allows future use of extension type

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • 🛠️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • 🧹 Code refactor
  • ✅ Build configuration change
  • 📝 Documentation
  • 🗑️ Chore

@kevmoo kevmoo requested a review from a team as a code owner June 22, 2024 00:58
@kevmoo
Copy link
Contributor Author

kevmoo commented Jun 22, 2024

@felangel – enable CI workflows?

@felangel
Copy link
Contributor

@felangel – enable CI workflows?

I’m not part of the organization anymore so I don’t have permissions unfortunately. @wolfenrain @alestiago can help 👍

@tomarra
Copy link
Contributor

tomarra commented Jun 25, 2024

Hi @kevmoo 👋 Thanks for opening this PR. Would you be able to fill in the description of the PR with more details on what the goal of this change is and how it accomplishes that? I added our normal PR template back into the description so all you should need to do is fill out the description section with those details for us to do a proper review.

kevmoo and others added 2 commits June 25, 2024 12:44
Co-authored-by: Jochum van der Ploeg <[email protected]>
Co-authored-by: Jochum van der Ploeg <[email protected]>
@kevmoo
Copy link
Contributor Author

kevmoo commented Jun 25, 2024

@tomarra – done!

@kevmoo
Copy link
Contributor Author

kevmoo commented Jun 29, 2024

Do ya'll have benchmarks we could look at?

@tomarra
Copy link
Contributor

tomarra commented Jul 1, 2024

Do ya'll have benchmarks we could look at?

We do not. There are some benchmarks that are out there which you may be able to run locally, https://github.com/sharkbench/sharkbench comes to mind given their website https://sharkbench.dev/web/dart-dartfrog, to help validate this.

@alestiago alestiago requested a review from wolfenrain August 13, 2024 09:11
@alestiago alestiago moved this from Community to Needs Triage in VGV Open Source 🦄 🧙🌟 Mar 4, 2025
@alestiago
Copy link
Contributor

alestiago commented Mar 19, 2025

I found this piece of documentation from the Flutter Style:

Generally speaking, Expando objects are a sign of an architectural problem. Carefully consider whether your usage is actually necessary. When your classes have clear documented ownership rules, there is usually a better solution.

Expando objects tend to invite code that is hard to understand because one cannot simply follow references to find all the dependencies.

This said, this usage could be an exception. Flutter itself still uses Expando in some occurrences.

@kevmoo
Copy link
Contributor Author

kevmoo commented Mar 20, 2025

I think it depends on usage. I wouldn't land this PR unless there were performance tests run first!

@felangel felangel added the performance Changes that improve performance label Aug 2, 2025
Copy link
Contributor

@felangel felangel left a comment

Choose a reason for hiding this comment

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

LGTM ✅

I ran some benchmarks locally and the Expando refactor does have a measurable performance impact.

For example, with a request body size of 1,071,472 bytes, and 100,000,000 calls to request.body, using Expando performed approximately 3% better (~500ms faster in the test I ran).

@kevmoo I expected to see a more significant performance improvement but since there is still a measurable performance gain and we're able to make the internal request final again, I think it's worth merging.

@felangel felangel changed the title chore: optimize Request.read perf: optimize Request.body Sep 30, 2025
@felangel felangel changed the title perf: optimize Request.body perf: optimize Request.read Sep 30, 2025
@felangel felangel merged commit ea8ddee into dart-frog-dev:main Sep 30, 2025
24 checks passed
@github-project-automation github-project-automation bot moved this from Needs Triage to Done in VGV Open Source 🦄 🧙🌟 Sep 30, 2025
@felangel felangel assigned kevmoo and unassigned wolfenrain Sep 30, 2025
@kevmoo
Copy link
Contributor Author

kevmoo commented Sep 30, 2025

It was a bit of an experiment on my side to see if this pattern would work.

It'd LOVE to know MEMORY impact, too. Might be interesting to look at.

@kevmoo kevmoo deleted the use_expando branch September 30, 2025 07:02
@felangel
Copy link
Contributor

100,000,000

Just took a quick look and the memory impact is much more significant in the test case I ran.

It was a bit of an experiment on my side to see if this pattern would work.

It'd LOVE to know MEMORY impact, too. Might be interesting to look at.

Just took a quick peak and memory impact seems to be more significant. I'll post some more detailed benchmarks/snapshots in a bit but thanks again for the contribution and glad we were finally able to land it 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Changes that improve performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants