Dunfey · Hotel WWDC as data, est. 1983
Front desk everything
Years
Topics

2021 System Services

WWDC21 · 23 min · System Services

Reduce network delays for your app

CPU performance and network throughput rates keep improving, but the speed of light is one limit that isn’t going any higher. Learn the APIs and best practices to maximize your app’s responsiveness and efficiency by keeping network round-trip times low and minimizing the number of round trips when performing network operations.

Watch at developer.apple.com ↗

Transcript all transcripts

Code shown on screen · 5 snippets

Fast open with TCP handshake swift · at 9:28 ↗
/* Allow fast open on the connection parameters */
parameters.allowFastOpen = true

let connection = NWConnection(to: endpoint, using: parameters)

/* Call send with idempotent initial data before starting the connection */
connection.send(content: initialData, completion: .idempotent)
connection.start(queue: myQueue)
Sockets with fast open swift · at 11:01 ↗
connectx(fd, ..., CONNECT_DATA_IDEMPOTENT | CONNECT_RESUME_ON_READ_WRITE, ...); // delay SYN
write(fd, ...); // SYN goes out with first data segment
Save round-trips when switching networks with Multipath TCP swift · at 13:35 ↗
// Multipath TCP
// Save multiple round-trips when switching networks

// On URLSessionConfiguration
let configuration = URLSessionConfiguration.default
configuration.multipathServiceType = .interactive

// On NWParameters
let parameters = NWParameters.tcp
parameters.multipathServiceType = .interactive
Background service type, App in foreground swift · at 20:09 ↗
//Use default  URLSession, set background on URLRequest
var request = URLRequest(url: myurl)
request.networkServiceType = .background

//Set service class on parameters to apply to the  NWConnection
let parameters = NWParameters.tls
parameters.serviceClass = .background
Time insensitive tasks running in background swift · at 20:10 ↗
//Configure background URL Session

lazy var urlSession: URLSession = {
    let configuration = URLSessionConfiguration.background(withIdentifier: "MySession")
    configuration.isDiscretionary = true
    return URLSession(configuration: configuration, delegate: self, delegateQueue: nil)
}()