title: vagrant ssh-config is very slow
body: <p>The <code>vagrant ssh-config</code> command takes more than 12 seconds:</p>
  
  <pre><code>host% time vagrant ssh-config
  Host default
    HostName 10.0.0.2
    User vagrant
    Port 22
    UserKnownHostsFile /dev/null
    StrictHostKeyChecking no
    PasswordAuthentication no
    IdentityFile /home/user/.vagrant.d/insecure_private_key
    IdentitiesOnly yes
    LogLevel FATAL
  
  1.614u 0.487s 0:12.27 17.0%     0+0k 0+24io 0pf+0w
  host% 
  </code></pre>
  
  <p>This is presumably what is causing <code>vagrant ssh</code> to also take 12 seconds (by comparison, <code>ssh -p2222 vagrant@localhost</code> does not use <code>vagrant ssh-config</code>, and takes only 1 second).</p>
  
  <p>My <code>Vagrantfile</code> is:</p>
  
  <pre><code># -*- mode: ruby -*-
  # vi: set ft=ruby :
  
  Vagrant.configure("2") do |config|
  
    config.vm.box              = "bento/ubuntu-18.10"
    config.vm.box_version      = "201906.18.0"
    config.vm.box_check_update = false
    config.vm.hostname         = "demo"
  
    config.vm.network :private_network, ip: "10.0.0.2"
    # enables, for example, 'ssh vagrant@10.0.0.2'
  
    # None of these actually work. Boo.
    #config.ssh.host = "10.0.0.2"
    #config.ssh.port = 22
    #config.ssh.username   = 'root'
    #config.ssh.password   = 'vagrant'
    #config.ssh.insert_key = 'true'
  
    config.vm.provider "virtualbox" do |vb|
      vb.name   = config.vm.hostname
      vb.memory = "2048"
      vb.cpus   = "2"
      vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    end
  
    # config.vm.synced_folder "../data", "/vagrant_data"
  
    config.vm.provision "shell", inline: &lt;&lt;-SHELL
      echo "Hello, World!"
    SHELL
  
  end
  </code></pre>
  
  <p>If I run <code>vagrant ssh-config --debug</code>, it prints the following before waiting about 11 seconds:</p>
  
  <pre><code> INFO runner: Preparing hooks for middleware sequence...
   INFO runner: 1 hooks defined.
   INFO runner: Running action: environment_load #&lt;Vagrant::Action::Builder:0x0000000001e95f60&gt;
  DEBUG checkpoint_client: starting plugin check
   INFO cli: CLI: [] "ssh-config" []
  DEBUG cli: Invoking command class: VagrantPlugins::CommandSSHConfig::Command []
  DEBUG checkpoint_client: waiting for checkpoint to complete...
  </code></pre>
  
  <p>Then it prints up to this point:</p>
  
  <pre><code> INFO base: VBoxManage path: VBoxManage
   INFO subprocess: Starting process: ["/usr/bin/VBoxManage", "--version"]
   INFO subprocess: Command not in installer, restoring original environment...
  DEBUG subprocess: Selecting on IO
  </code></pre>
  
  <p>and hangs for 0.5 seconds, and then prints some other stuff and the above lines again, and hangs for another 0.5 seconds, before finishing.</p>
  
  <p>I would expect <code>vagrant ssh-config</code> to be just querying Vagrant's data structure, and I would expect this to be efficiently implemented so that it can complete in a few milliseconds at most. Instead, it is doing something apparently quite involved.</p>
  
  <p>I noticed that other commands like <code>vagrant destroy --debug</code> have similar behavior. I.e., they have a long pause after <code>waiting for checkpoint</code> and shorter pauses after <code>Selecting on IO</code>.</p>
  
  <p>Were Vagrant commands such as <code>vagrant ssh-config</code> and <code>vagrant destroy</code> designed to be this slow? Any thoughts on how to make vagrant commands run faster? Can the slow parts be bypassed?</p>