Skip to content

Commit 30b8b6f

Browse files
balatmistral-vibe
andcommitted
Update inline contents design documentation
Clarify that inline_contents_max_bytes is configurable and document the validation process added for this configuration parameter. Adds: - Example configuration code - Configuration validation section - Updated testing section to include validation tests - Clarification that the threshold can be customized per repository Generated by Mistral Vibe. Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
1 parent 8151ddf commit 30b8b6f

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

doc/irmin-pack/design/inline_contents.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ For very small values (e.g., a single byte), this overhead can be larger than th
2828

2929
### Inlining Threshold
3030

31-
Content values are inlined when their **serialized size** plus 2 bytes of encoding overhead (1-byte variant tag + 1-byte varint length prefix) is less than the configured threshold. The default threshold is **48 bytes**.
31+
Content values are inlined when their **serialized size** plus 2 bytes of encoding overhead (1-byte variant tag + 1-byte varint length prefix) is less than the configured threshold. The default threshold is **48 bytes**, but this can be customized per repository.
3232

33-
The threshold is configured per-repo via `Backend.Repo.inline_contents_max_bytes`. A value of `0` disables inlining entirely.
33+
The threshold is configured per-repo via `Backend.Repo.inline_contents_max_bytes`. A value of `0` disables inlining entirely. The configuration also includes validation to ensure the threshold is non-negative.
34+
35+
Example configuration:
36+
```ocaml
37+
Irmin_pack.config ~inline_contents:true ~inline_contents_max_bytes:64 root
38+
```
3439

3540
### Inlining Decision
3641

@@ -138,9 +143,9 @@ The inline contents feature is tested in `test/irmin-pack/test_inline_contents.m
138143
2. **Correctness with inlining**: Data stored and retrieved correctly with inlining enabled
139144
3. **Content equivalence**: Same data produces same content values regardless of inlining
140145
4. **Structure verification**: Verifies that small contents are actually stored inline in the node structure
146+
5. **Configuration validation**: Ensures that invalid configuration values (negative thresholds) are properly rejected
141147

142148
## Future Work
143149

144-
- Configurable inlining threshold via config (currently hardcoded to 48 when enabled)
145150
- Automatic migration of existing small contents
146151
- Statistics/metrics for inline vs non-inline contents ratio

test/irmin-pack/test_inline_contents.ml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ module S = struct
3535
include Maker.Make (Schema)
3636
end
3737

38-
let config ~sw ~fs ?(readonly = false) ?(fresh = true) ~inline_contents root =
38+
let config ~sw ~fs ?(readonly = false) ?(fresh = true)
39+
?inline_contents_max_bytes ~inline_contents root =
3940
Irmin_pack.config ~sw ~fs ~readonly ~fresh
4041
~indexing_strategy:Irmin_pack.Indexing_strategy.minimal ~inline_contents
41-
root
42+
?inline_contents_max_bytes root
4243

4344
let info = S.Info.empty
4445

@@ -315,6 +316,26 @@ module Test_metadata = struct
315316
S_meta.Repo.close repo
316317
end
317318

319+
(** Test that zero inline_contents_max_bytes disables inlining *)
320+
let test_zero_inline_threshold ~fs () =
321+
let root = Eio.Path.(fs / "_build" / "test-inline-zero") in
322+
rm_dir root;
323+
Eio.Switch.run @@ fun sw ->
324+
let repo =
325+
S.Repo.v
326+
(config ~sw ~fs ~readonly:false ~fresh:true ~inline_contents:true
327+
~inline_contents_max_bytes:0 root)
328+
in
329+
let tree = S.Tree.empty () in
330+
let tree = S.Tree.add tree [ "small" ] "abc" in
331+
let commit = S.Commit.v repo ~parents:[] ~info tree in
332+
let hash = S.Commit.hash commit in
333+
let commit' = S.Commit.of_hash repo hash |> Option.get in
334+
let tree' = S.Commit.tree commit' in
335+
let small = S.Tree.find tree' [ "small" ] in
336+
Alcotest.(check (option string)) "small content" (Some "abc") small;
337+
S.Repo.close repo
338+
318339
let tests ~fs =
319340
let tc name f = Alcotest.test_case name `Quick f in
320341
[
@@ -324,4 +345,6 @@ let tests ~fs =
324345
tc "inlining structure" (test_inlining_structure ~fs);
325346
tc "inlining with non-default metadata"
326347
(Test_metadata.test_inlining_with_metadata ~fs);
348+
tc "zero inline threshold disables inlining"
349+
(test_zero_inline_threshold ~fs);
327350
]

0 commit comments

Comments
 (0)