Skip to content
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

Refactors out KVO usage on NSURLSessionTask #410

Merged
merged 3 commits into from
Sep 22, 2017
Merged

Conversation

garrettmoon
Copy link
Collaborator

This was causing various crashes due to what the internet suggests is
an Apple bug. Sadly, this means that we'll only be getting valid bps
and time to first byte on iOS 10 and 11. I think this is a reasonable
tradeoff however.

Should fix #390

@ghost
Copy link

ghost commented Sep 21, 2017

1 Warning
⚠️ This is a big PR, please consider splitting it up to ease code review.

Generated by 🚫 Danger

This was causing various crashes due to what the internet suggests is
an Apple bug. Sadly, this means that we'll only be getting valid bps
and time to first byte on iOS 10 and 11. I think this is a reasonable
tradeoff however.
@@ -21,8 +21,27 @@ typedef enum : NSUInteger {
lowQualityQPSThreshold:(float)lowQualityQPSThreshold
highQualityQPSThreshold:(float)highQualityQPSThreshold;

- (void)addTaskBPS:(float)bytesPerSecond endDate:(NSDate *)endDate;
- (float)currentBytesPerSecond;
- (void)processMetrics:(NSURLSessionTaskMetrics *)metrics forTask:(NSURLSessionTask *)task host:(NSString *)host;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to remove the host argument, and instead read it from task.currentRequest.URL.host?

@interface PINSpeedRecorder ()
{
NSCache *_speedMeasurements;
Copy link
Contributor

Choose a reason for hiding this comment

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

Put generics on this cache?

firstByte = metric.responseStartDate;
}
if ([requestEnd compare:metric.responseEndDate] != NSOrderedDescending) {
requestEnd = metric.responseEndDate;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This could be rephrased as requestStart = [requestStart earlierDate:metric.requestStartDate]; etc.

[self updateSpeedsForHost:host
bytesPerSecond:contentLength / [requestEnd timeIntervalSinceDate:requestStart]
startAdjustedBytesPerSecond:contentLength / [requestEnd timeIntervalSinceDate:firstByte]
timeToFirstByte:[firstByte timeIntervalSinceDate:requestStart]];
Copy link
Contributor

Choose a reason for hiding this comment

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

To reduce the amount of math in here, maybe just pass bytesPerSecond:measurement.bytesPerSecond etc?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Whoops, that measurement object was supposed to be deleted :)

@garrettmoon garrettmoon merged commit d1a9fef into master Sep 22, 2017
@workhardupc
Copy link

workhardupc commented Sep 26, 2017

@garrettmoon What time to releease new version?

@anirudhramanan
Copy link

@garrettmoon @workhardupc +1 This is causing quite a few crashes for us, and we're waiting for release of PINRemoteImage with this fix, along with a new version of Texture pointing to the new release.

@biocross
Copy link

biocross commented Oct 3, 2017

@appleguy
Copy link
Contributor

appleguy commented Oct 7, 2017

+1, this is one of the top crashes in my app too. Let's get a new version of PINRemoteImage and Texture pushed out.

@ronghai123
Copy link

@appleguy we also found the crash, but the latest version of Texture is not support the 'PINRemoteImage/WebP', '= 3.0.0-beta.13', so when you pushed out?

@xiaomaogong
Copy link

@garrettmoon we are also look forward to the latest version of Texture can support PinRemoveImage with '= 3.0.0-beta.13' , do you know when the release will happen?

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.

Add KVO to NSURLSessionTask may cause crash.
9 participants