Commit 0a852f9
committed
Compress emoji resource.
~10x file size reduction, 299KB → 27KB https://tijo.link/D28aSM.
Speed-wise I'm not concerned with this change. Did some light benchmarking and parsing is still _by far_ the slowest part of this, followed by reading from disk and then the decompression step. If anything, this is probably faster than before since 10x less is being read from disk.
Benchmark code:
/// Returns an array of all available emojis. Use this method to retrieve emojis for your own collection.
/// - Returns: Array of all emojis.
static public func getAllEmoji () -> [Emoji] {
let readStart = CACurrentMediaTime()
guard let url = Bundle.module.url(forResource: "Emoji Unicode 15.0", withExtension: "json.br"),
let compressedEmojiData = try? Data(contentsOf: url),
let brotliAlgorithm = NSData.CompressionAlgorithm(rawValue: NSData.CompressionAlgorithm.zlib.rawValue + 1) else {
// let emojiData = try? (compressedEmojiData as NSData).decompressed(using: brotliAlgorithm) as Data, // Brotli decompress https://tijo.link/WEQjXF
// let emoji = try? JSONDecoder().decode([Emoji].self, from: emojiData) else {
return []
}
print("Read: \(CACurrentMediaTime() - readStart)")
let decompStart = CACurrentMediaTime()
guard let emojiData = try? (compressedEmojiData as NSData).decompressed(using: brotliAlgorithm) as Data else { // Brotli decompress https://tijo.link/WEQjXF
return []
}
print("Decompress: \(CACurrentMediaTime() - decompStart)")
let parseStart = CACurrentMediaTime()
guard let emoji = try? JSONDecoder().decode([Emoji].self, from: emojiData) else {
return []
}
print("Parse: \(CACurrentMediaTime() - parseStart)")
return emoji
}
Benchmark results (debug build, sim, M3 Pro): https://tijo.link/a11f1B1 parent 6e1425d commit 0a852f9
4 files changed
Lines changed: 9 additions & 4 deletions
File tree
- Sources
- Resources
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
520 | 520 | | |
521 | 521 | | |
522 | 522 | | |
523 | | - | |
524 | | - | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
525 | 531 | | |
526 | 532 | | |
527 | 533 | | |
| |||
This file was deleted.
Binary file not shown.
0 commit comments