Speed up raw imports and add a per-import 16-bit toggle

Import raws four at a time to match the decoder pool, compress the 16-bit
sidecar with RLE on the libuv pool, and demosaic X-Trans files in a single
Markesteijn pass so Fuji imports no longer queue into decode timeouts. The
import dialog now offers 16-bit (default) or 8-bit per import, sent as
`?sidecar=0`, and the camera thumbnail and embedded-preview fallbacks no
longer drop to 8-bit samples or store a 0x0 photo.
This commit is contained in:
2026-12-02 03:25:53 +00:00
parent ea7b5b846c
commit fa0a7e64ef
11 changed files with 464 additions and 101 deletions
+24 -4
View File
@@ -232,9 +232,11 @@ storage, while quotas are stored per account in the database.
| `LUMINARY_INVITE` | *(empty)* | Shared registration code for teammates; personal invite links work without it |
| `LUMINARY_MAX_UPLOAD` | `314572800` (300 MB) | Largest accepted upload, in bytes |
| `LUMINARY_RAW_EDGE` | `6000` | Long edge of the editable JPEG proxy made from a raw |
| `LUMINARY_16BIT` | `1` | Also keep the decoded samples as a 16-bit PNG beside the raw proxy; `0` saves the disk and download it costs, at the price of grading an 8-bit source |
| `LUMINARY_16BIT` | `1` | Also keep the decoded samples as a 16-bit PNG beside the raw proxy; `0` saves the disk and download it costs, at the price of grading an 8-bit source. The import dialog can also turn it off for a single import |
| `LUMINARY_RAW_WORKERS` | `min(4, cores−1)` | Concurrent LibRaw decoders; each holds a worker and a few hundred MB |
| `LUMINARY_RAW_IDLE_MS` | `90000` | Idle decoders are disposed after this to release memory |
| `LUMINARY_RAW_XTRANS_QUALITY` | `1` | Markesteijn passes for Fujifilm X-Trans files, 1–3. Three passes costs 50 s on a 40 MP frame for detail the 6000 px proxy cannot show |
| `LUMINARY_RAW_TIMEOUT_MS` | `120000` | Ceiling on one demosaic, timed from when a worker starts the job rather than from the request |
| `LUMINARY_DENOISE_WORKERS` | `min(4, cores−1)` | Concurrent detail-denoise jobs (read directly from the environment) |
| `LUMINARY_QUOTA_BYTES` | `107374182400` (100 GiB) | Default per-account storage allowance |
| `LUMINARY_QUOTA_WARN_RATIO` | `0.9` | Fraction of the quota that triggers warnings, clamped to 0.5–0.99 |
@@ -879,7 +881,10 @@ The browser cannot demosaic camera raw, so the server does it during upload:
texture and applies `rgb_cam` in the grade shader, so the grade has 65,536 levels per
channel instead of 256. A photo without a sidecar — one imported before this existed,
a non-raw file, or a build with `LUMINARY_16BIT=0` — simply grades the JPEG, so
nothing breaks either way. The grid and Compare read the same samples: on first
nothing breaks either way. The import dialog offers this as **Import raws at 16-bit**,
checked by default; unchecking it for an import asks the server for the 8-bit path
(`?sidecar=0` on the upload), which decodes the same but skips the second encode and
its disk cost. The grid and Compare read the same samples: on first
request the server writes a camera-native tile the size of the JPEG thumbnail at
`previews/<id>.t16.png`, and Compare loads the full sidecar, so a loaded DCP profile
shows in every view of the photo. Preset previews do the same.
@@ -905,8 +910,11 @@ same matrix from a DCP `ColorMatrix1` — `inverse(rowNormalise(ColorMatrix · x
— matches LibRaw's `rgb_cam` to 2.2e-5 on a D700 NEF and 2.7e-5 on a 5D Mark II CR2.
**Parallel import.** Decoding runs in a bounded pool of LibRaw workers (default
`min(4, cores−1)`, `LUMINARY_RAW_WORKERS`), and the browser uploads several files at a
time. Each instance owns one worker thread; extra jobs queue. Idle instances are
`min(4, cores−1)`, `LUMINARY_RAW_WORKERS`). The browser keeps four raws in flight to
match that pool and queues the rest, so the server is never asked for more frames than it
can decode; camera JPEGs also go four at a time, since the browser decodes those itself.
Eight 12 MP NEFs took 20.8 s two at a time and 17.4 s four at a time (8 was 15.8 s, not
worth the extra memory). Each instance owns one worker thread; extra jobs queue. Idle instances are
disposed after `LUMINARY_RAW_IDLE_MS` and recreated on demand, so a burst of imports
does not pin memory forever. A decoder that reports a dead worker is recycled rather
than returned to the pool. Measured on this repo with 8 mixed raws (20 MP average):
@@ -917,6 +925,17 @@ than returned to the pool. Measured on this repo with 8 mixed raws (20 MP averag
| 4 | 5.2 s | 3.7× | ~2.5 GB |
| 8 | 3.5 s | 5.4× | ~3.5 GB |
Those are Bayer files. Fujifilm X-Trans frames behave differently in this wasm build: four
concurrent 40 MP X-Trans decodes each took ~65 s here against ~9 s on their own, so the
worker pool buys throughput in principle but not latency for that sensor. Two things
mattered more than the pool. LibRaw's default 3-pass Markesteijn demosaic took **49.9 s** on
one X-T5 frame; one pass takes **8.8 s** and is what `LUMINARY_RAW_XTRANS_QUALITY` selects.
And the 45 s decode timeout used to count time spent queued for a worker, so a parallel Fuji
import timed out in waves — every file in a wave fell back to the camera preview, and the
byte-scan fallback could hand back a truncated JPEG, which surfaced as a 0x0 photo. The
timeout now starts when a worker picks the job up, an abandoned worker is recycled instead
of being returned to the pool, and the fallback only stores bytes that actually decode.
Raise the worker count on a big machine; keep it low on a small VPS, where each worker
can hold a few hundred MB while decoding. `GET /api/health` reports the pool size and
busy count.
@@ -1137,6 +1156,7 @@ details, the isolation guarantees and the smoke tests (`windows/SMOKE-WINDOWS.ps
| `503` "The web build is missing" | `npm start` was run without `dist/`. Run `npm run build` first, or use `npm run dev` |
| Raw upload returns `422` | LibRaw could not decode the file and no embedded preview was found. Check `GET /api/health` → `raw.libraw`; install dependencies and confirm the camera is supported |
| Import is slow or the machine swaps | Lower `LUMINARY_RAW_WORKERS`; each decoder holds a worker and a few hundred MB |
| Fuji imports are slow or a Fuji file fails to import | X-Trans demosaic is the cost, not the network. `LUMINARY_RAW_XTRANS_QUALITY` defaults to 1 pass (~9 s for 40 MP); 3 is sharper and about five times slower. A file that still fails should now import from the camera preview — check its `decode` field for `embedded` |
| Emails never arrive | Gmail needs 2-Step Verification and an app password, not the account password. Use **Send test email**; admin-saved settings override the environment |
| Quota looks wrong after deleting | Trash still counts toward usage. Empty Trash to release the bytes |
| Cookies not marked `Secure` behind HTTPS | The proxy must forward `X-Forwarded-Proto: https` |