Answer a data file request without rescanning the manifest

Open
#2,635 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript

Research direction

Start with backend/src/routes/data.ts:257, services/manifest-source.ts, and services/manifest-queries.ts to trace how a file request scans the manifest and enforces visibility, version, and missing-object rules. The issue proposes a per-version path index but leaves its storage and build strategy for a plan to decide, so first compare those options while preserving the existing route behavior. Done means meeting the stated median and P90 CPU targets at comparable traffic and passing the existing data route tests unchanged.

Written by the indexing model from the issue text.

Description

Part of #2633.

A file request on data.nemar.org (/<id>/<version>/<path>, answered with a 302 to S3) costs 23 to 28 ms CPU at the median, 164 ms at P90, 578 ms at P99, with 62 MB median memory (nemar-api Metrics, last 24 h, 2026-12-02; 995k invocations, 1 "Exceeded CPU Time Limits", 1 "Exceeded Memory"). Workers CPU was $156.76 of the $274.44 November bill (7.87B CPU ms over about 76M requests).

Cause (from the code): each file request streams the version manifest through the scanner (queryManifest in backend/src/routes/data.ts:257, services/manifest-source.ts, services/manifest-queries.ts) to answer one path. The per-isolate memo is keyed by the query, so a client walking every file of a dataset, and a download manager splitting each file into Range requests (seen: range: bytes=158603733-), rescans the manifest for every request: O(files) work per file. #1502 moved to streaming to bound memory, which is right; what is missing is an index that answers one path without a scan.

Proposed direction (for the plan to decide): a per-version path index built once (at publish, or lazily on first scan) and stored where a lookup is cheap (edge cache, KV, R2 or D1 shards keyed by path hash), so the 302 becomes a lookup plus a presign. Range requests for the same path should reuse the resolution. Keep every integrity rule the manifest path enforces today (visibility gate, version resolution, missing-object handling, git-tracked files).

Acceptance: median CPU for a data-file 302 under 5 ms and P90 under 20 ms at comparable traffic, measured on nemar-api Metrics; no change in responses (existing data route tests pass unchanged).

Dominant language
TypeScript
Stars
0
Forks
1
Avg merge
4h 48m
Merged PRs (30d)
468

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nemarOrg/nemar-cli

All issues in nemarOrg/nemar-cli

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.