gradle / gradle-completion

Gradle tab completion for bash and zsh
MIT License
1.02k stars 133 forks source link

Eliminate overhead when caching many tasks in zsh #16

Open eriwen opened 7 years ago

eriwen commented 7 years ago

Generating zsh completion cache can be especially slow on builds with >10000 tasks. Commit https://github.com/eriwen/gradle-completion/commit/fc1459e8fa5317f76b4729f6d57ffc0210be8b38 helps a lot, but I've tested that caching takes about 1 second per 1000 tasks. This is much too long and can likely be mostly eliminated.

AWK may give us significantly improved performance, though the implementation will be more complex for handling unqualified tasks.

Something like this is a start.

     echo $gradle_tasks_output | awk '/^([[:lower:]][[:alnum:][:punct:]]*)([[:space:]]-[[:space:]]([[:print:]]*))?/ {
        task_name = match($0, /^[[:lower:]][[:alnum:][:punct:]]*/)
        task_description = match($0, /[[:space:]]-[[:space:]][[:print:]]*$/)
        line = sprintf("%s  - %s", $task_name, $task_description)
        if ($task_name ~ ^[[:alnum:]:]+:[[:alnum:]]+) { sprintf(":%s", $line); subproject_tasks+=( "${BASH_REMATCH[2]}" ) }
        else root_tasks+=( "$task_name" )
    }'