feat: loading templates performance improvements#6364
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughA singleton pattern for validator instances is introduced across multiple packages to prevent repeated instantiation and struct cache rebuilding. Validator initialization is centralized in new global variables for both options and templates. Additionally, template parsing logic is refactored to optimize memory usage and preprocessing, and matcher validation is rewritten to use reflection instead of YAML marshaling. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant TemplateParser
participant TemplateValidator (tplValidator)
participant MatcherValidator
participant OptionsValidator (validateOptions)
User->>TemplateParser: Parse template file (YAML/JSON)
TemplateParser->>TemplateValidator: Validate template struct (uses tplValidator)
TemplateValidator-->>TemplateParser: Validation result
User->>MatcherValidator: Validate Matcher struct
MatcherValidator->>MatcherValidator: Use reflection to extract fields
MatcherValidator-->>User: Validation result
User->>OptionsValidator: Validate options
OptionsValidator-->>User: Validation result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15 minutes Possibly related PRs
Suggested reviewers
Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
✨ Finishing Touches
🧪 Generate unit tests
🪧 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 comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
@coderabbitai list out the references that call the method/func updated by this PR. |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chainI'll help you find all the references to the methods and functions updated by this PR. Let me search through the codebase to identify where these updated components are called. 🏁 Script executed: Length of output: 43006 @dwisiswant0 Here are all the references that call the methods/functions updated by this PR: 1. ValidateOptions Function ReferencesUpdated in: Called from:
2. Matcher.Validate() Method ReferencesUpdated in: Called from:
3. Template Marshal/Unmarshal Methods ReferencesUpdated in: These methods (
4. Template Parsing Function ReferencesUpdated in: ParseTemplate/parseTemplate called from:
5. Validator Singleton UsageNew singletons created:
These performance improvements reduce the overhead of creating new validator instances for each validation operation, which should result in faster template loading and validation across the entire Nuclei codebase. 🐰✨ |
dwisiswant0
left a comment
There was a problem hiding this comment.
Noice! Got perf optimized up to 45.83% on mem, and around 1.84–2.05x faster speed.
diff:
… loading-performance-improvements-v2
Proposed changes
Checklist
Summary by CodeRabbit
Refactor
Chores