-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[ios] #3979 compress telemetry events #5490
Conversation
Awesome, these results look quite promising! You should go ahead and add a copy of NSData+GZIP's license to our list of licenses. Looks like the license in the repo is slightly different and more up-to-date. We also already include the original zlib license, so I think we’re covered there. @1ec5 mentioned prefixing as a thing we should do, as we’ve done with Reachability, which became NSData+GZIP’s files should also probably live in a subfolder at |
So it turns out we already have a simple interface to zlib in the codebase, in src/mbgl/util/compression.hpp. (It's used to compress and decompress tile data, part of the reason we already include the zlib license in our LICENSE file.) The header is currently private to mbgl, but I don't see any reason we couldn't move it to include/mbgl/util/ and use it within the SDK. compression.hpp uses std::string to hold the compressed data, but it's trivial to dump that buffer into an NSData. /cc @kkaefer |
Exposed the zlib interface we already had in include/mbgl/util/compression.hpp and got some interesting results
|
255e230
to
9c7e25e
Compare
Noticed that the compressed data was corrupt so even though we don't need it for the iOS SDK, I had to add |
9c7e25e
to
11b5be0
Compare
{ | ||
NSString *dataString = [[NSString alloc] initWithData:self encoding:NSUTF8StringEncoding]; | ||
|
||
std::string *string = new std::string([dataString UTF8String]); |
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.
C++ types should be allocated on the stack, whenever possible, rather than the heap.
11b5be0
to
5b41dbf
Compare
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
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.
- Nit: missing newline at the end.
It looks like you’ve copied src/mbgl/util/compression.hpp to include/mbgl/util/compression.hpp. Instead, you should move the file there. The convention is that headers in include/ are public (to SDK code), while headers in src/ can only be used in the SDK. Once you delete src/mbgl/util/compression.hpp, you’ll need to update compression.cpp to include |
|
||
- (float)randomFloatBetween:(float)lowerBound and:(float)upperBound { | ||
float diff = upperBound - lowerBound; | ||
return (((float) (arc4random() % ((unsigned)RAND_MAX + 1)) / RAND_MAX) * diff) + lowerBound; |
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.
nit: you might consider using arc4random_uniform
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.
Hrm, good to know. 💭
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.
Good one but since I want lat/lng I'm probably gonna go with drand48
.
I'm grabbing the value as integer after that because NSArray/NSDictionary -isEqualToDictionary/Array:
returns false despite the content being the same. Any idea why?
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.
Comparisons between floats often fail due to floating-point representations being imprecise. That’d be my first guess. If that turns out to be the case, try multiplying the latitude and longitude by enough decimal places that the imprecision wouldn’t matter much in reality, then floor the values. See this table to get an idea of how much precision you need.
👍 |
It's worth noting that this is a non-standard way of using HTTP; theoretically our client cannot know that the server supports |
You're right @kkaefer. I guess we could verify supported |
@frederoni not saying we should do anything else, I just wanted to make everyone aware that this is something we explicitly need to support in our server (and we already do). |
4a00f84
to
67537a4
Compare
WiP
Things to consider:
License for dependency (zlib)An event in the following test case is
lat, lng, timestamp
with randomized values.*Compressing one event actually increases the size of data on top of using unnecessary CPU cycles.
👀 @boundsj @friedbunny @1ec5