perf: reduce excessive openat syscalls during scan run #127
Labels
No labels
coordination/cross-repo
coordination/needed
effort
large
effort
medium
effort
small
meta/duplicate
meta/planning
meta/wontfix
priority
high
priority
low
priority
medium
session
blocker
session
handover
session
next
status
blocked
status
done
status
in-progress
status
review
status
to-go
type
admin
type/architecture
type
bug
type
config
type
deployment
type
docs
type/documentation
type
enhancement
type
feature
type
handover
type
infrastructure
type
installation
type
maintenance
type
migration
type
research
type
security
type/task
type/tech-debt
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
DAW/fragjan#127
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Goal
Reduce the number of file system
opencalls during a scan run.Currently fragjan performs ~26,000
openatsyscalls for 26 files and 774 checks.At 100 runs per day this amounts to ~2.6 million unnecessary file system operations.
Root Causes
Two independent issues in
core/runner/init.lua:1. Repeated directory walk per rule
mod_collect.collect_filesis called once per rule. Each call performs a fullrecursive file system walk of the scan target. With ~70 rules the same directory
tree is walked ~70 times.
2.
requireinside rule looppcall(require, rule.check.primitive)is called inside the rule loop.Although Lua caches loaded modules in
package.loaded, the lookup itselfmay still trigger file system probes on each call when the module is not
yet cached (first run) or due to package.path traversal overhead.
Acceptance Criteria
collect_filesis called once per unique(pattern, file_path, excludes, includes)combination and results are cached for the duration of the runopenatsyscall count reduces significantly (target: proportional to actual file count, not rule count)Technical Notes
Cache key for file collection:
pattern .. "|" .. (file_path or "") .. "|" .. table.concat(excludes, ",") .. "|" .. table.concat(includes, ",")Primitive cache: simple table keyed by primitive name, populated before the rule loop in
core/runner/init.lua.Measured baseline: 26,408
openatcalls, 2.74s wall clock, 5.5 MB RSS for 26 files / 774 checks.Full strace breakdown
Complete syscall profile reveals the real cost distribution:
newfstatat and getdents64 together account for 66% of syscall time.
The collect_files cache fix will reduce all three categories, not just openat --
since each directory walk also triggers stat and getdents calls.
Ratio getdents64 / openat ~= 2x confirms the repeated walk per rule.
Approach
Walk the directory tree once at the start of the run, build an in-memory file set,
then all rule checks work against that set instead of hitting the filesystem repeatedly.
This eliminates redundant getdents64 and newfstatat calls entirely for the per-rule phase.