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

Adding support for automatically skipping cancelation if the amount l… #364

Merged
merged 6 commits into from
May 26, 2017

Conversation

garrettmoon
Copy link
Collaborator

…eft to be downloaded is less than the average time to first byte.

Putting this up in favor of #357

…eft to be downloaded is less than the average time to first byte.
@ghost
Copy link

ghost commented May 25, 2017

🚫 CI failed with log

@ghost
Copy link

ghost commented May 25, 2017

🚫 CI failed with log

break;

case NSURLSessionTaskStateCompleted:
NSAssert(self.startTime != 0, @"Expect that task was started before it's completed.");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I might say > 0 here.

@@ -35,6 +35,8 @@ typedef void (^PINURLSessionDataTaskCompletion)(NSURLSessionTask * _Nonnull task

@property (atomic, weak, nullable) id <PINURLSessionManagerDelegate> delegate;

- (NSTimeInterval)weightedTimeToFirstByteForHost:(nonnull NSString *)host;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would benefit from a brief documentation comment.

if (metric.requestStartDate == nil || metric.responseStartDate == nil) {
//Only evaluate requests which completed their first byte.
valid = NO;
break;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like you could drop the valid flag and just return here.

NSTimeInterval timeToFirstByte;
[self lock];
timeToFirstByte = [[_timeToFirstByteCache objectForKey:host] doubleValue];
if (timeToFirstByte <= 0 + DBL_EPSILON) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can drop the lock earlier (here).


- (void)storeTimeToFirstByte:(NSTimeInterval)timeToFirstByte forHost:(NSString *)host
{
[self lock];
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if you can get away without locking. NSCache supports concurrent access, and the logic below is sufficiently fuzzy that missing/overwriting a measurement probably won't be super meaningful.

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.

None yet

2 participants