Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
fi

- name: go test
run: go test ./... -race -count=1 -timeout 300s
run: go test ./... -race -count=1 -timeout 240s

security:
runs-on: ubuntu-latest
Expand Down
17 changes: 15 additions & 2 deletions bench/score.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bench

import (
"context"
"encoding/json"
"fmt"
"io"
Expand All @@ -15,6 +16,7 @@ import (
"github.com/BurntSushi/toml"
"github.com/noeljackson/deepsec/internal/core"
"github.com/noeljackson/deepsec/internal/scanner"
scannerast "github.com/noeljackson/deepsec/internal/scanner/ast"
)

type ScoreOptions struct {
Expand Down Expand Up @@ -224,12 +226,22 @@ func Score(taskIDs []string, opts ScoreOptions) (*RunResult, error) {
noise[m.Slug()] = m.NoiseTier()
}

// Build one wazero runtime up front and reuse it across every
// scoreTask. Wazevo's WASM compile is ~10s per task with all 12
// grammars; without sharing, a 30-task corpus blows past CI's
// 5-minute test timeout.
astRT, err := scannerast.NewRuntime(context.Background(), scannerast.DefaultGrammars())
if err != nil {
return nil, fmt.Errorf("init shared AST runtime: %w", err)
}
defer astRT.Close(context.Background())

now := time.Now().UTC().Format("20060102T150405Z")
outDir := filepath.Join(opts.OutDir, now)
result := &RunResult{}
agg := accumulator{}
for _, id := range taskIDs {
tr, err := scoreTask(id, opts.TasksDir, outDir, opts.CandidateExplosion, noise, opts.ExtraMatcherPaths)
tr, err := scoreTask(id, opts.TasksDir, outDir, opts.CandidateExplosion, noise, opts.ExtraMatcherPaths, astRT)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -263,7 +275,7 @@ type scoredTask struct {
slugNoisy map[string]int
}

func scoreTask(id, tasksDir, outDir string, explosionThreshold float64, noise map[string]scanner.NoiseTier, extraMatcherPaths []string) (scoredTask, error) {
func scoreTask(id, tasksDir, outDir string, explosionThreshold float64, noise map[string]scanner.NoiseTier, extraMatcherPaths []string, astRT *scannerast.Runtime) (scoredTask, error) {
taskDir := filepath.Join(tasksDir, id)
key, err := LoadAnswerKey(filepath.Join(taskDir, "answer.yaml"))
if err != nil {
Expand Down Expand Up @@ -291,6 +303,7 @@ func scoreTask(id, tasksDir, outDir string, explosionThreshold float64, noise ma
MatcherOnly: cfg.MatcherOnly,
MatcherExclude: cfg.MatcherExclude,
ExtraMatcherPaths: extraMatcherPaths,
SharedASTRuntime: astRT,
})
if err != nil {
return scoredTask{}, err
Expand Down
37 changes: 25 additions & 12 deletions internal/scanner/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ type Options struct {
// re-evaluated even when both its content and the matcher pack are
// unchanged since the last scan.
ForceRescan bool
// SharedASTRuntime lets a caller hoist the wazero runtime across
// many Scan calls — bench.scoreTask reuses one runtime across all
// fixtures instead of paying the ~10s wazevo compile per task. When
// nil, Scan constructs a per-call runtime as before.
SharedASTRuntime *scannerast.Runtime
}

// LanguageStat is one row of the per-language scan summary.
Expand Down Expand Up @@ -85,12 +90,16 @@ func Scan(opts Options) (*Outcome, error) {
return nil, err
}
active, skipped := splitGated(reg, tech, opts.Root)
astRT, err := runtimeForActiveAST(active, reg)
if err != nil {
return nil, err
}
if astRT != nil {
defer astRT.Close(context.Background())
astRT := opts.SharedASTRuntime
if astRT == nil {
built, err := runtimeForActiveAST(active, reg)
if err != nil {
return nil, err
}
if built != nil {
defer built.Close(context.Background())
}
astRT = built
}

files, err := WalkProject(opts.Root)
Expand Down Expand Up @@ -198,12 +207,16 @@ func ScanFiles(opts Options, files []string, source string) (*FilesOutcome, erro
return nil, err
}
active, skipped := splitGated(reg, tech, opts.Root)
astRT, err := runtimeForActiveAST(active, reg)
if err != nil {
return nil, err
}
if astRT != nil {
defer astRT.Close(context.Background())
astRT := opts.SharedASTRuntime
if astRT == nil {
built, err := runtimeForActiveAST(active, reg)
if err != nil {
return nil, err
}
if built != nil {
defer built.Close(context.Background())
}
astRT = built
}

packHash := reg.PackHash()
Expand Down
Loading