Skip to content

Hooks API to track parameters and sizes #1601

@s-kanev

Description

@s-kanev

At Google, with other compression algorithms, we've found it useful to be able to cheaply gather telemetry for compression uasge -- things like compressed / decompressed sizes and algorithm settings (e.g. compression level, window size). Aggregating these fleetwide (in a way similar to CPU or heap profiles) lets us look for optimization opportunities like spurious compression.

I'm proposing adding a simple hooks API to zstd that lets one do that. It basically amounts to users registering a callback that gets called at the end of (de)compressing every block. Perhaps with a signature similar to the one in snappy:

typedef void (*ZSTD_hook) (const char* algorithm, size_t uncompressedSize, size_t compressedSize);

where algorithm is a short string like "zstd:3,15" (compression level, log window).
Of course, when no callback is registered, the overhead should be ~0, even for short compression calls.

Any objections to adding something like that?

If not, we can talk about what the actual API could look like, and how would users register a callback. (I have a simple prototype, but wouldn't pretend to know about all use cases of zstd that could be affected).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions