Cache the generateCipherKey function and add profiling support to lint#18
Cache the generateCipherKey function and add profiling support to lint#18
Conversation
The lint/apply/dry-run had become slow, and profiling showed up that we were calling generateCipherKey many times as the yaml base grows. This patch adds caching to the generateCipherKey function avoiding the regeneration for the same password/salt. This reduces our lint run time from 17s to 0.4s
|
Caution Review failedThe pull request is closed. WalkthroughAdds optional CPU profiling and timing to the lint command, switches to an error-returning validation path, and expands linting to include template rendering checks. Introduces error-map merging utilities. Implements a thread-safe cached key-derivation mechanism in VaultDecryptor and updates decryption to use it. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant U as User
participant CLI as cmd/lint
participant L as config_lint
participant P as pprof
U->>CLI: run lint [--cpu-profile=file]
alt cpu profiling enabled
CLI->>P: pprof.StartCPUProfile(file)
Note over CLI,P: Profiling active
end
CLI->>L: ValidateWithError(cfg)
L->>L: Lint(cfg) = validateReferences + validateTemplates
L-->>CLI: error or nil
CLI->>CLI: record duration and print
alt profiling active
CLI->>P: pprof.StopCPUProfile()
end
CLI-->>U: exit with code (0/1)
sequenceDiagram
autonumber
participant C as Caller
participant VD as VaultDecryptor
participant Cache as vd.cache
participant KDF as PBKDF2
C->>VD: Decrypt(vaultData)
VD->>VD: parse salt from vaultData
VD->>Cache: lookup key by salt-hex (RLock)
alt cache hit
Cache-->>VD: CipherKey
else cache miss
VD->>KDF: derive from vd.password + salt
KDF-->>VD: CipherKey
VD->>Cache: store (Lock)
end
VD-->>C: plaintext or error
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (3)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
The lint/apply/dry-run had become slow, and profiling showed up that we were calling generateCipherKey many times as the yaml base grows.
This patch adds caching to the generateCipherKey function avoiding the regeneration for the same password/salt. This reduces our lint run time from 17s to 0.4s
Summary by CodeRabbit
New Features
Performance Improvements
Reliability