Skip to content

chore: optimize Request.read #1410

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

kevmoo
Copy link

@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
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 👍

@@ -158,3 +154,5 @@ class Request {
return Request._(_request.change(headers: headers, path: path, body: body));
}
}

final _bodyFutureExpando = Expando<Future<String>>('dart_frog.request.body');
Copy link
Member

Choose a reason for hiding this comment

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

Not that familiar with Expandos, would love to see a description on the PR to explain how this improves performance

Copy link
Author

Choose a reason for hiding this comment

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

You all would have to measure it.

On the VM, they're pretty cheap. And now you're avoiding copying everything all the time which should be a lot cheaper

@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 <jochum@vdploeg.net>
Co-authored-by: Jochum van der Ploeg <jochum@vdploeg.net>
@kevmoo
Copy link
Author

kevmoo commented Jun 25, 2024

@tomarra – done!

@kevmoo
Copy link
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
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!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
Status: Needs Triage
Development

Successfully merging this pull request may close these issues.

5 participants