internal/pkg: cache computed identifiers
All checks were successful
Test / Create distribution (push) Successful in 49s
Test / Sandbox (push) Successful in 3m1s
Test / ShareFS (push) Successful in 4m56s
Test / Sandbox (race detector) (push) Successful in 5m21s
Test / Hpkg (push) Successful in 5m30s
Test / Hakurei (push) Successful in 5m53s
Test / Hakurei (race detector) (push) Successful in 7m56s
Test / Flake checks (push) Successful in 1m57s

This eliminates duplicate identifier computations. The new implementation also significantly reduces allocations while computing identifier for a large dependency tree.

Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
2026-01-15 22:05:24 +09:00
parent 088d35e4e6
commit 3499a82785
9 changed files with 276 additions and 199 deletions

View File

@@ -50,7 +50,7 @@ func TestExec(t *testing.T) {
nil,
nil, nil,
)),
pkg.MustPath("/.hakurei", false, stubArtifact{
pkg.MustPath("/.hakurei", false, &stubArtifact{
kind: pkg.KindTar,
params: []byte("empty directory"),
cure: func(t *pkg.TContext) error {
@@ -67,7 +67,7 @@ func TestExec(t *testing.T) {
check.MustAbs("/opt/bin/testtool"),
[]string{"testtool"},
pkg.MustPath("/proc/nonexistent", false, stubArtifact{
pkg.MustPath("/proc/nonexistent", false, &stubArtifact{
kind: pkg.KindTar,
params: []byte("doomed artifact"),
cure: func(t *pkg.TContext) error {
@@ -124,7 +124,7 @@ func TestExec(t *testing.T) {
nil,
nil, nil,
)),
pkg.MustPath("/.hakurei", false, stubArtifact{
pkg.MustPath("/.hakurei", false, &stubArtifact{
kind: pkg.KindTar,
params: []byte("empty directory"),
cure: func(t *pkg.TContext) error {
@@ -150,7 +150,7 @@ func TestExec(t *testing.T) {
check.MustAbs("/opt/bin/testtool"),
[]string{"testtool"},
pkg.MustPath("/", true, stubArtifact{
pkg.MustPath("/", true, &stubArtifact{
kind: pkg.KindTar,
params: []byte("empty directory"),
cure: func(t *pkg.TContext) error {
@@ -176,13 +176,13 @@ func TestExec(t *testing.T) {
check.MustAbs("/work/bin/testtool"),
[]string{"testtool"},
pkg.MustPath("/", true, stubArtifact{
pkg.MustPath("/", true, &stubArtifact{
kind: pkg.KindTar,
params: []byte("empty directory"),
cure: func(t *pkg.TContext) error {
return os.MkdirAll(t.GetWorkDir().String(), 0700)
},
}), pkg.MustPath("/work/", false, stubArtifact{
}), pkg.MustPath("/work/", false, &stubArtifact{
kind: pkg.KindTar,
params: []byte("empty directory"),
cure: func(t *pkg.TContext) error {
@@ -207,13 +207,13 @@ func TestExec(t *testing.T) {
check.MustAbs("/opt/bin/testtool"),
[]string{"testtool", "layers"},
pkg.MustPath("/", true, stubArtifact{
pkg.MustPath("/", true, &stubArtifact{
kind: pkg.KindTar,
params: []byte("empty directory"),
cure: func(t *pkg.TContext) error {
return os.MkdirAll(t.GetWorkDir().String(), 0700)
},
}, stubArtifactF{
}, &stubArtifactF{
kind: pkg.KindExec,
params: []byte("test sample with dependencies"),
@@ -222,7 +222,7 @@ func TestExec(t *testing.T) {
pkg.ID{0xfe, 0},
nil,
nil, nil,
), stubArtifact{
), &stubArtifact{
kind: pkg.KindTar,
params: []byte("empty directory"),
@@ -255,7 +255,7 @@ func newTesttool() (
testtoolDestroy func(t *testing.T, base *check.Absolute, c *pkg.Cache),
) {
// testtoolBin is built during go:generate and is not deterministic
testtool = overrideIdent{pkg.ID{0xfe, 0xff}, stubArtifact{
testtool = overrideIdent{pkg.ID{0xfe, 0xff}, &stubArtifact{
kind: pkg.KindTar,
cure: func(t *pkg.TContext) error {
work := t.GetWorkDir()