Skip to content

Defer statistics update until first access to improve performance#21643

Open
dwelch-r7 wants to merge 1 commit into
rapid7:masterfrom
dwelch-r7:lazy-load-stats
Open

Defer statistics update until first access to improve performance#21643
dwelch-r7 wants to merge 1 commit into
rapid7:masterfrom
dwelch-r7:lazy-load-stats

Conversation

@dwelch-r7

Copy link
Copy Markdown
Contributor

Description

Defer stats calculation until we need it, this results in running msfconsole with the -q flag spinning up a 0.3-0.5s faster, I haven't removed the stats from the banner but I think we should consider it since it's really not that useful and it's adding time to the boot up process.

Verification Steps

    • Start msfconsole normally (without -q) — banner should display correct module counts as before
    • Start msfconsole -q -x 'exit' — should boot and exit without error
    • In msfconsole, run banner command — module counts should display correctly
    • Run bundle exec rspec spec/lib/msf/base/simple/statistics_spec.rb — all 11 examples pass

Test Evidence

with -q

hyperfine  --warmup 3 "bundle exec ruby ./msfconsole -q -x 'exit'"                                                                                                     
Benchmark 1: bundle exec ruby ./msfconsole -q -x 'exit'
  Time (mean ± σ):      3.732 s ±  0.034 s    [User: 2.561 s, System: 1.242 s]
  Range (min … max):    3.679 s …  3.777 s    10 runs

without -q

hyperfine  --warmup 3 "bundle exec ruby ./msfconsole -x 'exit'"                                                                                                        
Benchmark 1: bundle exec ruby ./msfconsole -x 'exit'
  Time (mean ± σ):      4.263 s ±  0.094 s    [User: 3.008 s, System: 1.319 s]
  Range (min … max):    4.178 s …  4.485 s    10 runs

Environment

Field Details
Operating System macOS (26.5.2)
Target Software/Hardware Metasploit Framework (Ruby 3.3.8)

AI Usage Disclosure

Kiro

Pre-Submission Checklist

  • No sensitive information (IP addresses, credentials, API keys, hashes) in code or documentation
  • Tested on the target environment specified in the Environment section above
  • Included RSpec tests for library changes
  • Read the CONTRIBUTING.md and module acceptance guidelines

@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Metasploit Kanban Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants