Trying to use ZIPFoundation Swift package, I came across this:

Note: There is a large performance discrepancy between Debug and Release builds of ZIP Foundation. The main performance bottleneck is the code that calculates CRC32 checksums. This codepath executes slowly when Swift optimizations are turned off (-Onone). To avoid long wait times when debugging code that extracts archives, the skipCRC32 flag can be set. To learn more about the skipCRC32 parameter, please refer to the documentation strings of the Archive.extract and FileManager.unzipItem methods. Skipping CRC32 checks should only be enabled during debugging.

I look crc32(checksum:) implementation to figure out what’s wrong with it.

Firstly, I proposed PR: Speed up crc32 calculation in performance test ~4 times.

I started to think about a way to speed up crc32 calculation even further, possibly used SIMD extensions.

Have found swift-crc32c swift package which uses SSE 4.2 instruction set if running on an Intel CPU that supports it.

Failed to find something similar for ARM. But I have found this in linux crc32-ce-glue.c: Accelerated CRC32(C) using ARM CRC, NEON and Crypto Extensions instructions and crc32c-intel_glue.c: Using hardware provided CRC32 instruction to accelerate the CRC32 disposal.

So there’s some opensourced foundation for Swift package for hardware accelerated CRC32 for both Intel and ARM.

This worth bookmarking Ethernet CRC32 calculations. Includes brief CRC tutorial.

This from Android worth bookmarking crc32-arm64.c - CRC32 and CRC32C using optional ARMv8 instructions.

Zlib in Chromium include both ARMv8 and Intel crc32_simd.c.

This is interesting Stackoverflow question: How to detect crc32 on aarch64.

Interesting repo validating Chromium’s SIMD CRC.

And finally, this is pure gold A PAINLESS GUIDE TO CRC ERROR DETECTION ALGORITHMS which might be useful in attempt to implement crc32 from scratch or in attempt understand and/or improve implementation from others.

The best option would be implementing CRC32 package with Swift SIMD Vector Types.

Today’s finding: ZIPFoundation’s CRC32 is exactly what happening in crc32.c. Precalculated table matches first part from crc32.h (precalculated with crc32.c file).