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

Consider using brotli compression instead of gzip #4502

Open
Tracked by #111
philipphofmann opened this issue Nov 5, 2024 · 2 comments
Open
Tracked by #111

Consider using brotli compression instead of gzip #4502

philipphofmann opened this issue Nov 5, 2024 · 2 comments
Milestone

Comments

@philipphofmann
Copy link
Member

Description

The Cocoa SDK currently uses gzip to compress its HTTP requests to Sentry.

NSData *_Nullable sentry_gzippedWithCompressionLevel(
NSData *data, NSInteger compressionLevel, NSError *_Nullable *_Nullable error)
{
uInt length = (uInt)[data length];
if (length == 0) {
return [NSData data];
}
/// Init empty z_stream
z_stream stream;
stream.zalloc = Z_NULL;
stream.zfree = Z_NULL;
stream.opaque = Z_NULL;
stream.next_in = (Bytef *)(void *)data.bytes;
stream.total_out = 0;
stream.avail_out = 0;
stream.avail_in = length;
int err;
err = deflateInit2(
&stream, compressionLevel, Z_DEFLATED, (16 + MAX_WBITS), 9, Z_DEFAULT_STRATEGY);
if (err != Z_OK) {
if (error) {
*error = NSErrorFromSentryError(kSentryErrorCompressionError, @"deflateInit2 error");
}
return nil;
}
NSMutableData *compressedData = [NSMutableData dataWithLength:(NSUInteger)(length * 1.02 + 50)];
Bytef *compressedBytes = [compressedData mutableBytes];
NSUInteger compressedLength = [compressedData length];
/// compress
while (err == Z_OK) {
stream.next_out = compressedBytes + stream.total_out;
stream.avail_out = (uInt)(compressedLength - stream.total_out);
err = deflate(&stream, Z_FINISH);
}
[compressedData setLength:stream.total_out];
deflateEnd(&stream);
return compressedData;
}

It uses the zlib for the compression.

#if __has_include(<zlib.h>)
# import <zlib.h>
#endif

When bumping our min SDK version to iOS 13, we can consider switching to the Apple Compression framework and use brotli, which is slightly faster and better at compression JSON. Furthermore, we can remove the dependency libz.tbd.

63AF656C1ED87B8C00EBCFF7 /* libz.tbd in Frameworks */,

@brustolin
Copy link
Contributor

Actually, the dependency libz.tbd is not really necessary.
But if Brotli is native of iOS 13, I agree with the change, we just need to check whether our server support it.

@BYK
Copy link
Member

BYK commented Nov 5, 2024

Relay supports gzip, brotli, and zstd. Python SDK has added support for Brotli recently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

3 participants