Skip to content

Suppress Pry history loading only if Pry is already defined#21648

Merged
adfoster-r7 merged 1 commit into
rapid7:masterfrom
dwelch-r7:remove-pry-require
Jul 7, 2026
Merged

Suppress Pry history loading only if Pry is already defined#21648
adfoster-r7 merged 1 commit into
rapid7:masterfrom
dwelch-r7:remove-pry-require

Conversation

@dwelch-r7

Copy link
Copy Markdown
Contributor

Here's your PR description:


Description

Defer Pry loading in Rex::Ui::Text::Shell#run to avoid paying the require 'pry' cost on every msfconsole boot. Saves about 0.2s on my machine.

The run method previously did an unconditional require 'pry' solely to set Pry.config.history_load = false — a config that prevents Pry from loading its own history when binding.pry is used. This loaded the entire Pry gem at boot even though most sessions never use Pry.

The change replaces require 'pry' with if defined?(Pry), which only sets the config when Pry has already been loaded elsewhere.

Verification Steps

    • Start msfconsole normally — verify it boots without errors
    • Run the pry command inside msfconsole — verify Pry session starts and Pry history isn't polluted with framework commands

Test Evidence

# Before (with require 'pry' at boot):
hyperfine  --warmup 3 "bundle exec ruby ./msfconsole -q -x 'exit'"                                                                                                                                                        
Benchmark 1: bundle exec ruby ./msfconsole -q -x 'exit'
  Time (mean ± σ):      4.337 s ±  0.080 s    [User: 3.055 s, System: 1.351 s]
  Range (min … max):    4.237 s …  4.485 s    10 runs

# After
hyperfine  --warmup 3 "bundle exec ruby ./msfconsole -q -x 'exit'"                                                                                                                                                        
Benchmark 1: bundle exec ruby ./msfconsole -q -x 'exit'
  Time (mean ± σ):      4.155 s ±  0.058 s    [User: 2.986 s, System: 1.272 s]
  Range (min … max):    4.048 s …  4.232 s    10 runs

Environment

Field Details
Operating System macOS (26.5.2)
Ruby version 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
  • 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 7, 2026
@adfoster-r7 adfoster-r7 added the rn-no-release-notes no release notes label Jul 7, 2026
@adfoster-r7 adfoster-r7 merged commit 050265a into rapid7:master Jul 7, 2026
20 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Metasploit Kanban Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rn-no-release-notes no release notes

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants