DEV Community

Cover image for A Token-Efficient Way to Send Time-Series Data into LLMs
Manas Mudbari
Manas Mudbari

Posted on

A Token-Efficient Way to Send Time-Series Data into LLMs

If you’ve ever pushed time-series data (metrics, logs, network streams, sensor readings) into an LLM, you’ve probably noticed that even small datasets can get expensive and slow very quickly.

Not because the data is huge, but because of how it gets tokenized.

This post is about a representation experiment we’ve been running to reduce that overhead, what didn’t work, and what seems to help.

The Problem We Ran Into

Time-series data is repetitive by nature:

  • timestamps move forward predictably
  • values often change slowly
  • schema repeats on every row

Humans immediately see the pattern but LLMs don’t.

Most LLM tokenizers are optimized for natural language, not numerical streams. Two numbers that look almost identical to us can tokenize very differently. Repeating structure (timestamps, keys, braces) quietly eats context and cost.

At small scale, it’s annoying, but at scale, it becomes an infrastructure problem.

What We Tried (and What Didn’t Help Much)

Before building anything new, we tried existing formats:

  • JSON (baseline)
  • CSV (more compact, but still verbose)
  • TOON (interesting idea, but still text that gets re-tokenized)

In practice, TOON didn’t materially reduce token usage once everything was still passed as plain text into an LLM. The structure was different, but the tokenizer behavior didn’t improve much.

That was the key realization: compression alone isn’t the problem — tokenization is.

Math was our intuition

If you’ve taken calculus or physics, this will feel familiar.

Think about motion:

  • Position → where something is
  • Velocity → how position changes
  • Acceleration → how velocity changes

Now map that to time-series data:

  • raw values = position
  • differences between values = velocity (delta)
  • differences between deltas = acceleration (delta-of-delta)

Most real-world time-series data has low acceleration. Values drift; timestamps tick forward regularly.

So instead of repeating full values and timestamps, we started experimenting with representing changes.

TSLN: A Token-Aware Representation

That experiment turned into TSLN (Time-Series Lean Notation).

At a high level, it’s a text-based serialization that:

  • stores deltas instead of repeating full values
  • stores delta-of-delta for regular timestamps
  • declares schema once instead of repeating it
  • stays human-readable and streamable

The key difference from “just compression” is that it’s designed to be tokenization-aware. Smaller, bounded numbers and less repeated syntax lead to far fewer tokens once the model sees the input.

In early benchmarks, the same datasets used up to ~80% fewer tokens compared to JSON. That directly translated into lower cost and better effective context windows when calling LLMs.

Code and Next Steps

We’ve open-sourced Go and Node.js implementations under the MIT license so it’s easy to experiment or drop into existing pipelines.

I’m currently expanding the benchmarks across more datasets, tokenizers, and workloads, and plan to publish a more formal preprint once that’s done.

If you work with:

  • time-series data
  • LLM pipelines
  • serialization or streaming systems

I’d genuinely love feedback — especially edge cases, comparisons we should run, or prior art I may have missed.

Top comments (0)