Skip to content

Commit 7a237eb

Browse files
committed
internal/cuetxtar: do not load the root cuelang.org/go CUE module
When loading cuetxtar files, such as cue/testdata/eval/let.txtar, we want to use cue/load to load the list of CUE files in the txtar. cue/load will attempt to walk the chain of parent directories to find a valid CUE module, and since the vast majority of these txtar files contain only CUE files, we'd load cuelang.org/go repeatedly. This didn't cause any failures or issues per se, but reading parent directories works against Go's per-package test caching, and loading the root cue.mod/module.cue over and over again is wasteful. As measured by benchcmd and benchstat, adt.TestEvalV3 sees a moderate speed-up, as every subtest begins with a cue/load call via cuetxtar. │ old │ new │ │ sec/op │ sec/op vs base │ TestEvalV3 544.4m ± 10% 452.1m ± 6% -16.94% (p=0.000 n=12) │ old │ new │ │ user-sec/op │ user-sec/op vs base │ TestEvalV3 1007.7m ± 12% 753.5m ± 5% -25.23% (p=0.000 n=12) │ old │ new │ │ sys-sec/op │ sys-sec/op vs base │ TestEvalV3 45.15m ± 9% 52.16m ± 19% ~ (p=0.266 n=12) │ old │ new │ │ peak-RSS-bytes │ peak-RSS-bytes vs base │ TestEvalV3 80.03Mi ± 2% 36.43Mi ± 2% -54.47% (p=0.000 n=12) Signed-off-by: Daniel Martí <[email protected]> Change-Id: Ife342fd0b4dd09f350aace8b668c2def7725c453 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1218102 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Roger Peppe <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 4cb33de commit 7a237eb

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

internal/cuetxtar/txtar.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ func loadWithConfig(a *txtar.Archive, dir string, cfg load.Config, args ...strin
329329
overlay[filepath.Join(dir, f.Name)] = load.FromBytes(f.Data)
330330
}
331331

332+
// Don't walk the chain of parent directories; this busts Go's test cache,
333+
// and also leads to loading the root module "cuelang.org/go" repeatedly for no reason.
334+
cfg.ModuleRoot = "."
332335
cfg.Dir = dir
333336
cfg.Overlay = overlay
334337

0 commit comments

Comments
 (0)