apache_datasketches/cpc/init.rs
1use apache_datasketches_sys::cpc_sketch::ffi as sys;
2
3/// Eagerly initializes CPC's global decompression tables, used during
4/// serialization/deserialization.
5///
6/// Upstream lazily self-initializes these tables on first use via a
7/// function-local static with a dynamic initializer; C++11 onward
8/// guarantees this lazy path is initialized exactly once even under
9/// concurrent access (concurrent callers block until the first caller
10/// finishes, they don't race), so there is no correctness hazard from
11/// skipping `init()`. Calling it eagerly is a latency optimization: it
12/// moves the one-time cost of allocating and building the tables off the
13/// hot path, and avoids every thread that happens to hit the lazy path
14/// first stalling behind whichever one wins the initialization race.
15pub fn init() {
16 sys::cpc_init().expect(
17 "cpc_init should never fail: the decompression tables it builds are \
18 derived from fixed, compile-time-constant permutation data",
19 );
20}