Skip to content

Project VIC import: find files from one listing per folder, show progress - #322

Merged
charpy4n6 merged 8 commits into
mainfrom
fix/vic-import-speed
Oct 29, 2026
Merged

charpy4n6 merged 8 commits into
mainfrom
fix/vic-import-speed

Conversation

@charpy4n6

@charpy4n6 charpy4n6 commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

What

A large Project VIC case export looked frozen during import. On a 627 MB file of 380,000 entries, the screen sat on "Scanning sources" and nothing was written to the case for minutes. On one examiner's machine it ran past 30 minutes.

Two causes:

  • projectvic.iter_records resolved every entry's path on its own. On Windows, Path.resolve() is five GetFinalPathName calls and two link reads per path. Profiled over 30,000 entries, that was 11.8 of 14.0 s (84%).
  • import_vic reported no progress until every entry was registered.

The fix

  • _Locator: each folder is resolved once and listed once, and each entry is a lookup in that listing. An existing file takes the name as the disk spells it, which is what resolve() returned on a case-insensitive volume, so rows are keyed on the same paths as before.
  • Progress: import_vic(progress=...) calls progress(n, what) every 2,000 entries, with what as "Reading Project VIC entries" and then "Registering files". ingest_sources passes it through, and the web job shows it in place of "Scanning sources".

Measured

Windows 11, Python 3.12, on a synthetic 627 MB VIC file of 380,000 entries with a file present for each:

v2026.5.5 this PR
Read all entries 128.2 s 9.1 s
Whole import_vic 216.3 s 95.6 s
First progress shown at the end after 4.5 s
Rows registered 380,000 380,000

The remaining time is writing the rows (upsert_file), which this PR doesn't change. A frozen exe built from this branch imported the examiner's real export on their machine. That machine's own times weren't recorded.

Behavior notes

  • A file that is itself a symbolic link isn't followed any more, where resolve() followed it. The entry's folder is still resolved.
  • An ingest_sources progress callback now has to accept an optional second argument. The two callers in the tree are the web job (updated) and the CLI (passes none).

Tests

  • New tests/test_vic_import_speed.py: paths and existence match what resolve() gave, a differently-cased name takes the disk's spelling, files_dir is listed too, and the progress calls and web job messages are covered.
  • Full suite locally on Windows: 1115 passed, 7 skipped. One test was deselected because it needs Windows symlink privilege.
  • The lint check reports no new warnings, and line endings are LF.

Also in this PR (found while testing on a 218,838-file VIC case)

  • Processing bar starts at 0 (2c99b5c): the ingest's entry count no longer carries into processing.
  • No LZC check for videos with a video extension (fa2c7d9): every video was opened, one after another, before processing started. That held the case at 0% for minutes.
  • Sniffed videos go to the batched video pass (0fcd7d2): a file found to be a video only during processing got a child process of its own. 200 clips named .dat: 75.9 s before, 9.1 s after.
  • "Files processed at once" on the ingest forms (f6b582b): default 4, up to the machine's logical processors. Documented in MANUAL.md and help.html.
  • Folder check kept across processing writes (26f6296): every gallery poll re-read all paths during processing, so the screen's count froze.
  • OpenCV on one thread per worker (2a25120): on 800 photos with screening, 8 workers went from 16.9 to 20.9–24.1 files/s.

Known limit: workers are threads of one process. On a 32-processor machine, 32 ran slower than 16 (about 22 against about 60 files/s). Scaling past 16 needs processes, which will be a separate PR.

🤖 Generated with Claude Code

charpy4n6 and others added 8 commits October 29, 2026 14:55
…ress

A 627 MB VIC case export (380,000 entries) sat on "Scanning sources" with
nothing written for minutes. iter_records resolved every entry's path on
its own, and on Windows Path.resolve() is five GetFinalPathName calls and
two link reads per path: 84% of the time spent reading the file. Nothing
reported progress until every entry was registered.

Each folder is now resolved once and listed once (projectvic._Locator),
and each entry is a lookup in that listing. An existing file keeps the
spelling the disk gives it, which is what resolve() returned, so a row is
keyed on the same path as before. import_vic takes progress(n, what) and
reports "Reading Project VIC entries" and "Registering files"; the web
job shows it.

Measured on Windows 11, Python 3.12, a synthetic 627 MB file of 380,000
entries with a file present for each: reading the entries 128.2 s -> 9.1 s,
the whole import 216.3 s -> 95.6 s, first progress after 4.5 s, and the
same 380,000 rows either way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The ingest now reports progress for a Project VIC import, counting up to
every entry, and _run_job moved to processing without resetting done.
The bar then read n/n, 100%, before a single file was processed, while
the real per-file count only arrives every 25 files. Every other place
that starts a process stage already sets done=0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Before processing a single file, process() opened every video, one after
another, to read four bytes and see whether it was a Snapchat LZC bundle.
On an examiner's machine a 218,838-file Project VIC case sat at 0% for
over four minutes on exactly that line (pipeline.py:780 > lzc.is_lzc,
every 30 s snapshot), with almost no disk reads, where each open of a
file was slow.

An LZC bundle is named by hash with no extension, so a .mp4 or .mov is
not one: only a video without a video extension is opened now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A file registered as something else that turns out to be a video (a
Project VIC entry whose extension or MIME type does not say video) was
decoded in a child process of its own, one per file. A 30 s snapshot of
an examiner's run showed all four workers in extract_video_isolated at
about 1.7 files a second. Such a file now has its hashes and kind written
and joins the batched video pass, 20 to a process. An LZC bundle's video
is still decoded where it is, since its bytes are not the row's file.

200 ten-frame clips named .dat, from source on Windows: 75.9 s -> 9.1 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Processing worked on 4 files at once whatever the machine, and the video
pass stopped at 4 child processes whatever was asked. On a 16-core
machine a 218,838-file Project VIC case processed at about 43 files a
second with most of the processor idle.

Processing options on the New case and Add evidence forms gain "Files
processed at once", default 4, up to the machine's logical processors
(at most 32); the form shows that count from os.cpu_count(). The web job
takes it as options.workers, and the video pass follows it. MANUAL.md and
help.html describe it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
relink.folder_status kept its answer only until the next write, so
during processing, which writes every few files, each gallery poll read
every path of the case again. A 30 s snapshot of a 218,838-file Project
VIC case showed all four request threads in relink._source_paths, and
the gallery's count stopped updating while processing went on.

CaseDB.derived_by_paths keeps the answer until a file is added or
removed, or a path or source is written (path_writes), checking with one
count only after a write. A repeat with nothing written still reads no
row of files.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
OpenCV runs each call (the face detector, resizes) on threads of its
own, one per processor by default, so several workers each asked for
every processor and fought over them. Measured on 800 photos with face
and skin screening, 8 logical processors: 4 workers 17.0 files/s, 8
workers 16.9, and 8 workers with OpenCV on one thread each 20.9 to 24.1.
The setting is restored when the picture pass ends.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@charpy4n6
charpy4n6 merged commit 7b550d7 into main Oct 29, 2026
7 checks passed
@charpy4n6
charpy4n6 deleted the fix/vic-import-speed branch October 30, 2026 23:13
stark4n6 pushed a commit to stark4n6/GLEAPP that referenced this pull request Nov 2, 2026
abrignoni#322 found each entry's file in one listing per folder, matched with
os.path.normcase, which folds case only on Windows. On a Mac volume, and on
FAT or exFAT anywhere, a name that differs from the disk's in case or in how
an accented letter is composed is the same file, and Path.exists found it
before abrignoni#322; the listing called it missing. A name that matches a listed one
only loosely is now asked of the filesystem. A name with no loose match costs
nothing more: 16,000 entries read in the same 139 to 142 ms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant