Skip to content

server: /load with backend=polars reads the whole file into memory, once per session #993

Open

Description

@paddymul

Problem

/load with backend: "polars" reads the whole file into memory with pl.read_parquet (buckaroo/server/data_loading_polars.py:77), and each session holds its own copy. Two sessions on the same path hold two copies.

Measured on a 1.2M-row, 4-column, 11.5 MB parquet: the server's RSS rose by 151 MB on the first /load, and by another 63 MB when a second session loaded the same file. Once warm, repeat POSTs to the same session add about 4 MB each rather than a frame's worth, so the previous frame is released; the cost is per session.

/load_expr reads through DataFusion one window at a time and holds no table.

Impact

tallyman's largest entry is 78,024,179 rows by 43 columns, 3.7 GB of parquet. Through /load each open grid on it would hold that whole table in the buckaroo process, once per session. That rules out moving tallyman's grid from /load_expr to /load for its larger entries.

Suggested fix

  • Open the file with pl.scan_parquet and apply search, sort and slice to the LazyFrame per window, collecting only the window. The mode: "lazy" path (handle_infinite_request_lazy) already pages a LazyFrame, but without the buckaroo dataflow.
  • Compute stats with one lazy collect over the scan.
  • Failing that, share one frame per path across sessions, so the cost is per file instead of per grid.

#769 (lazy polars pipeline, one collect per run) may cover part of this.

Context

Found while checking whether tallyman's grid can move from /load_expr to /load with backend: "polars", on buckaroo 0.15.8 (same code on main at 992fdb3).

The other gaps from the same check: #992, #994, #995, #996.

Activity

  1. paddymul commented on Oct 2, 2026

    @paddymul
    CollaboratorAuthor

    Measured on a 10.8M-row × 43-column parquet (28 String columns, 409 MB), PolarsServerSampling.pre_limit = False, one run each:

    step time memory
    pl.read_parquet 0.56 s estimated_size 2.63 GB, max RSS 6.4 GB
    search "NY" (9.5M matches), one window 1.46 s / 0.90 s
    search with 0 matches, one window 0.42 s / 0.26 s
    sort on a String column, one window 4.47 s max RSS 17.8 GB

    The first figure in each search row is the window at row 0 and the second the window at row 5,000. Every window request repeats the filter, and with a sort, with_row_index().sort(...) (data_loading_polars.py:138) sorts the whole filtered frame again for each window. Keeping the sorted order (or its arg_sort indices) per search and sort would remove the per-window sort.

    Scaling linearly by rows, the 78,024,179-row entry would need about 46 GB of RSS just to hold the frame, on a 48 GB machine.

    Stats don't need the frame in memory. One select over pl.scan_parquet with the streaming engine computes length, null count, exact distinct, empty count and min/max/mean/std for all 43 columns of the 78M-row file in 4.4 s, with a peak RSS of 13.7 GB (#999).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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