LMDB storage layout: monolithic event values vs. per-rep sub-databases
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 重构
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 领域
- database, performance
调研方向
The issue identifies LMDBWriter, LMDBDataset._update_cache, merge_files, and a linked profiling task as relevant entry points. Start by locating those components and profiling full-value deserialization, DataLoader throughput, and the time and disk size involved in adding a representation. Use the measurements at realistic dataset sizes to inform whether a sub-database refactor is warranted; the issue does not specify a profiling task URL or test command.
由索引模型根据 Issue 内容生成。
描述
Context
LMDBWriter and LMDBDataset currently store every event as a single LMDB key/value pair, with all extractors and all precomputed DataRepresentations bundled into one serialized blob:
- Key:
str(event_no).encode("utf-8") - Value: serialized dict
{ "<pulsemap_extractor_name>": {col: [values...], ...}, "<truth_extractor_name>": {col: [value], ...}, ...other extractors... "data_representations": { "GraphDefinition": <torch_geometric.Data>, ...one entry per stored rep... }, }
Worth opening a discussion on whether this is the right long-term layout.
Where the monolithic layout hurts
- Reading when you only want one rep.
LMDBDataset._update_cachedeserializes the entire value even whenpre_computed_representation="GraphDefinition". The raw tables (~3.5 KB) are decoded for nothing. - Adding or removing a representation after the fact requires deserializing every event value, mutating its
data_representationsdict, and reserializing the whole thing back — even though only the new rep is actually new on disk. For ~10M events at ~500 µs round-trip that's hours single-threaded. - Pickle of small torch tensors is the dominant cost. Each tensor carries its own torch metadata overhead, so a
Datawith ~10 small tensors is much slower to (de)serialize than the equivalent number of plain bytes.
What a sub-database layout would look like
LMDB natively supports multiple named sub-databases per env via env.open_db(name=...) (with max_dbs > 1). The natural split is:
defaultsub-DB:{event_no → {extractor_name: dict-of-lists, ...}}(raw tables, nodata_representationskey)- One sub-DB per representation field name (
KNNGraph,GraphDefinition, ...):{event_no → Data} - Metadata keys (
__meta_serialization__,__meta_data_representations__) stay where they are.
Wins
- Adding a representation becomes a pure insert into the new rep's sub-DB. No reads of existing data, no rewriting of raw tables.
- Reads only deserialize what was asked for.
LMDBDataset(pre_computed_representation="GraphDefinition")would do a single B+tree lookup in theGraphDefinitionsub-DB and skip the raw tables entirely. - Removing a representation is cheap — drop the sub-DB or delete its keys.
- Smaller values in the hot path are friendlier to LMDB's page cache.
Costs
- Two B+tree lookups per event if a caller wants raw tables AND a rep. Still O(log N) and amortized cheap, but real.
- Breaking change for existing on-disk LMDBs. A migration helper would be needed (or a one-time "flatten" pass).
- More moving parts in
LMDBWriter,LMDBDataset,merge_files, and the metadata schema (need to know which sub-DB names to open).
Other tradeoffs worth noting
- Lookup time is not a concern: LMDB is a B+tree, lookup is O(log N) — essentially constant for any realistic dataset size. The cost discussion above is about value size and (de)serialization, not key lookup.
- Parallelizing writers is bounded by LMDB's single-writer-per-env lock. A compute pool + serial writer helps the current monolithic layout; a sub-DB layout would help more, because workers would only ship the new
Datarather than a full re-serialized event value.
Decision needed
Whether the sub-DB refactor is worth the breaking change. Numbers are needed before deciding — see the linked profiling task.
Tasks
- Profile the current layout to determine whether the costs above are actually felt in practice, before committing to any refactor:
- Per-event deserialization time (full value vs. just the rep)
- DataLoader throughput at typical batch sizes /
num_workerssettings - End-to-end wall time of an "add one rep to N events" operation
- On-disk size before/after adding a rep
If profiling shows the costs are negligible at realistic dataset sizes, the sub-DB refactor isn't worth doing.
- 主要语言
- Python
- 星标
- 117
- 派生
- 115
- 平均合并
- 2 天 21 小时
- 30 天内合并 PR
- 1
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
graphnet-team/graphnet 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
graphnet-team/graphnet#933 ·
-
Spring clean未关闭
难度 5/5 一周以上 新手友好度 25/100
graphnet-team/graphnet#927 · 1 条评论 ·
-
Time for a new version release v1.8.1可能重新可做 @Aske-Rosted 于 75 天前认领,目前没有进行中的 PR。 未关闭decision
graphnet-team/graphnet#924 · 已指派 1 人 ·
-
Make kaggle checkpoints part of the CI可能重新可做 @sevmag 于 75 天前认领,目前没有进行中的 PR。 未关闭bug
graphnet-team/graphnet#921 · 2 条评论 · 已指派 1 人 ·
-
decision deferred
难度 5/5 一周以上 新手友好度 25/100
graphnet-team/graphnet#919 ·
查看 graphnet-team/graphnet 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
NL-BioImaging/biomero#136 ·
维护者通常 1 天内回复
-
Grayscale PNGs with partial transparency can turn gray pixels white可能已有人在做 @ktz03 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
-
enhancement good first issue help wanted
难度 2/5 1-3 小时 新手友好度 78/100
floorianmb/tidywise#5 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
eclipse-score/tools#82 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复