dbx icon indicating copy to clipboard operation
dbx copied to clipboard

Show completion is slow

Open ribugent opened this issue 3 years ago • 0 comments

Expected Behavior

Adding the completions to the shells should be fast

Current Behavior

I've noticed that adding the completions in the shell start-up files, causes a 1 second delay.

Steps to Reproduce (for bugs)

It's easy to test it using time, here are my tests (I'm using a fish shell) and it's pretty clear that the slowness is caused by dbx

 î‚° time dbx --show-completion bash
_dbx_completion() {
    local IFS=$'
'
    COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \
                   COMP_CWORD=$COMP_CWORD \
                   _DBX_COMPLETE=complete_bash $1 ) )
    return 0
}

complete -o default -F _dbx_completion dbx

________________________________________________________
Executed in    1.08 secs      fish           external
   usr time  958.61 millis    0.00 micros  958.61 millis
   sys time  113.81 millis  886.00 micros  112.93 millis

 î‚° time dbx --show-completion zsh
#compdef dbx

_dbx_completion() {
  eval $(env _TYPER_COMPLETE_ARGS="${words[1,$CURRENT]}" _DBX_COMPLETE=complete_zsh dbx)
}

compdef _dbx_completion dbx

________________________________________________________
Executed in    1.06 secs      fish           external
   usr time  904.69 millis  646.00 micros  904.05 millis
   sys time  149.29 millis  115.00 micros  149.18 millis

 î‚° time dbx --show-completion fish
complete --command dbx --no-files --arguments "(env _DBX_COMPLETE=complete_fish _TYPER_COMPLETE_FISH_ACTION=get-args _TYPER_COMPLETE_ARGS=(commandline -cp) dbx)" --condition "env _DBX_COMPLETE=complete_fish _TYPER_COMPLETE_FISH_ACTION=is-args _TYPER_COMPLETE_ARGS=(commandline -cp) dbx"

________________________________________________________
Executed in    1.05 secs      fish           external
   usr time  921.08 millis  663.00 micros  920.41 millis
   sys time  129.37 millis  116.00 micros  129.26 millis

 î‚° time dbx --show-completion powershell
Import-Module PSReadLine
Set-PSReadLineKeyHandler -Chord Tab -Function MenuComplete
$scriptblock = {
    param($wordToComplete, $commandAst, $cursorPosition)
    $Env:_DBX_COMPLETE = "complete_powershell"
    $Env:_TYPER_COMPLETE_ARGS = $commandAst.ToString()
    $Env:_TYPER_COMPLETE_WORD_TO_COMPLETE = $wordToComplete
    dbx | ForEach-Object {
        $commandArray = $_ -Split ":::"
        $command = $commandArray[0]
        $helpString = $commandArray[1]
        [System.Management.Automation.CompletionResult]::new(
            $command, $command, 'ParameterValue', $helpString)
    }
    $Env:_DBX_COMPLETE = ""
    $Env:_TYPER_COMPLETE_ARGS = ""
    $Env:_TYPER_COMPLETE_WORD_TO_COMPLETE = ""
}
Register-ArgumentCompleter -Native -CommandName dbx -ScriptBlock $scriptblock

________________________________________________________
Executed in    1.04 secs      fish           external
   usr time  936.32 millis  325.00 micros  936.00 millis
   sys time   99.40 millis   46.00 micros   99.36 millis

 î‚° time dbx --show-completion pwsh
Import-Module PSReadLine
Set-PSReadLineKeyHandler -Chord Tab -Function MenuComplete
$scriptblock = {
    param($wordToComplete, $commandAst, $cursorPosition)
    $Env:_DBX_COMPLETE = "complete_powershell"
    $Env:_TYPER_COMPLETE_ARGS = $commandAst.ToString()
    $Env:_TYPER_COMPLETE_WORD_TO_COMPLETE = $wordToComplete
    dbx | ForEach-Object {
        $commandArray = $_ -Split ":::"
        $command = $commandArray[0]
        $helpString = $commandArray[1]
        [System.Management.Automation.CompletionResult]::new(
            $command, $command, 'ParameterValue', $helpString)
    }
    $Env:_DBX_COMPLETE = ""
    $Env:_TYPER_COMPLETE_ARGS = ""
    $Env:_TYPER_COMPLETE_WORD_TO_COMPLETE = ""
}
Register-ArgumentCompleter -Native -CommandName dbx -ScriptBlock $scriptblock

________________________________________________________
Executed in    1.06 secs      fish           external
   usr time  948.15 millis  814.00 micros  947.34 millis
   sys time  110.50 millis  119.00 micros  110.38 millis

Context

Your Environment

  • OS: Arch Linux
  • python version: 3.10.7
  • dbx version used: 0.7.5
  • Databricks Runtime version: N/A

The dbx was installed from AUR

ribugent avatar Sep 28 '22 06:09 ribugent