News for hackers. Stuff that matters.

v0y4g3r

You nailed it
WriteRequest::timeseries is a vector (https://github.com/prometheus/prometheus/blob/main/prompb/re...) and the repeated file `Timeseries::labels` and `Timeseries::samples` are reused across different timeseries. You don't have to alloc a new vector for the lables and samples for each new timeseries instance.
The Go version is not a naive implementation, it's also the well optimized version from VictoriaMetrics.
It's technically `safe` as long as you never access the decoded struct once the original bytes is dropped.

I believe that how `unsafe` works, the programmer, instead of compiler, ensures safety.

I think no. In this particular case it involves how Rust handles lifetimes compared to other languages with garbage collector.

Essentially it's a comparison between reference counting and tracing garbage collection based on reacheability.

FlatBuffers does the trick as a better replacement to ProtoBuf when running in some resource-critical devices. We were working on a project that leverage Arrow IPC (internally FlatBuffers) and shared memory to collect metrics on edge devices with limit CPU and memory, hopefully we can open source it soon.

But in this case the format is defined by [Prometheus](https://github.com/prometheus/prometheus/blob/main/prompb/re...) and we just adopt that.