-
-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calculate upload rate #1029
Calculate upload rate #1029
Conversation
4da96c3
to
7dd05e9
Compare
0ff96c3
to
d662e48
Compare
@gilest this is looking great! Quick question, should we be throttling this calculation instead of updating it on every event? |
// Divide by elapsed time to get bytes per millisecond | ||
const rate = bytesTransferredSinceLastUpdate / timeElapsedSinceLastUpdate; | ||
|
||
file.rates = [...file.rates, rate]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be more performant to use a TrackedArray
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. I say leave it unless we have problems.
@@ -51,6 +52,11 @@ export class UploadFile { | |||
this.#name = value; | |||
} | |||
|
|||
/** The current speed in ms that it takes to upload one byte */ | |||
get rate() { | |||
return estimatedRate(this.rates); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Work done in plain functions for unit-testing purposes.
Interesting question 🤔 So each time a
Beyond that, no work is done. We'll only do a rate calculation if one of the Obviously if a So I don't think we need to do any throttling. It's also worth noting that the demo simulation sends 10 progress events per second. Probably it's a bit less often in real-world HTTP uploads. |
@gilest yeah seems performant enough and we can always kick the tires a bit and see if we need to tweak it later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great to me. Thanks for taking it over the finish line!
Continuation of work by @RobbieTheWagner in #1015
Methodology
progress
events occurFile.rate
propertyQueue.rate
propertyAll rates are in bytes/ms.
Demo
Recent improvements to the demo page make this much easier to validate and test.
Screen.Recording.2023-12-01.at.3.07.05.PM.mov