{"action":"created","issue":{"url":"https://api.github.com/repos/junegunn/fzf/issues/548","repository_url":"https://api.github.com/repos/junegunn/fzf","labels_url":"https://api.github.com/repos/junegunn/fzf/issues/548/labels{/name}","comments_url":"https://api.github.com/repos/junegunn/fzf/issues/548/comments","events_url":"https://api.github.com/repos/junegunn/fzf/issues/548/events","html_url":"https://github.com/junegunn/fzf/issues/548","id":150498752,"number":548,"title":"Loading completion.bash is so slow on Cygwin","user":{"login":"gene-pavlovsky","id":2841193,"avatar_url":"https://avatars.githubusercontent.com/u/2841193?v=3","gravatar_id":"","url":"https://api.github.com/users/gene-pavlovsky","html_url":"https://github.com/gene-pavlovsky","followers_url":"https://api.github.com/users/gene-pavlovsky/followers","following_url":"https://api.github.com/users/gene-pavlovsky/following{/other_user}","gists_url":"https://api.github.com/users/gene-pavlovsky/gists{/gist_id}","starred_url":"https://api.github.com/users/gene-pavlovsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gene-pavlovsky/subscriptions","organizations_url":"https://api.github.com/users/gene-pavlovsky/orgs","repos_url":"https://api.github.com/users/gene-pavlovsky/repos","events_url":"https://api.github.com/users/gene-pavlovsky/events{/privacy}","received_events_url":"https://api.github.com/users/gene-pavlovsky/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-04-23T00:11:46Z","updated_at":"2016-04-23T02:39:20Z","closed_at":"2016-04-23T02:36:50Z","body":"- Category\r\n    - [ ] fzf binary\r\n    - [ ] fzf-tmux script\r\n    - [ ] Key bindings\r\n    - [X] Completion\r\n    - [ ] Vim\r\n    - [ ] Neovim\r\n    - [ ] Etc.\r\n- OS\r\n    - [ ] Linux\r\n    - [ ] Mac OS X\r\n    - [X] Windows (Cygwin)\r\n    - [ ] Etc.\r\n- Shell\r\n    - [X] bash\r\n    - [ ] zsh\r\n    - [ ] fish\r\n\r\nOn my Cygwin system, enabling the completion file (which adds `**` handling) really slows down bash startup. The completion script takes 0.5 s to execute (on Core i7!). I've done some digging and traced the problem down to one line - https://github.com/junegunn/fzf/blob/master/shell/completion.bash#L282\r\nSpecifically, in `eval \"$(printf \"$orig\" \"$func\")\"` the `$()` command substitution creates a subshell (I guess?), I've replaced this call with `time echo \"$(printf \"$orig\" \"$func\")\"` and each call to printf takes 0.012 ms, since there are many commands in a loop that call this function, total time is over 0.4 s on my laptop. I guess this is due to `fork` on Cygwin being so slow - on Linux `completion.bash` executes very quickly.\r\n\r\nBy the way, while I was inserting debugging `echo` into completion.bash, I've noticed the entire file is sourced every time a completion is invoked for a command it was not invoked before (again, producing a significant slowdown on Cygwin). E.g., I put `echo Adding FZF completions` just before the _fzf_defc invokations. When I run bash, I can see that message as bash_completion initializes. When I type `scp ` and press Tab twice, I can see that message appear again! How does it work? I couldn't find the code which sources the script itself again."},"comment":{"url":"https://api.github.com/repos/junegunn/fzf/issues/comments/213653563","html_url":"https://github.com/junegunn/fzf/issues/548#issuecomment-213653563","issue_url":"https://api.github.com/repos/junegunn/fzf/issues/548","id":213653563,"user":{"login":"junegunn","id":700826,"avatar_url":"https://avatars.githubusercontent.com/u/700826?v=3","gravatar_id":"","url":"https://api.github.com/users/junegunn","html_url":"https://github.com/junegunn","followers_url":"https://api.github.com/users/junegunn/followers","following_url":"https://api.github.com/users/junegunn/following{/other_user}","gists_url":"https://api.github.com/users/junegunn/gists{/gist_id}","starred_url":"https://api.github.com/users/junegunn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/junegunn/subscriptions","organizations_url":"https://api.github.com/users/junegunn/orgs","repos_url":"https://api.github.com/users/junegunn/repos","events_url":"https://api.github.com/users/junegunn/events{/privacy}","received_events_url":"https://api.github.com/users/junegunn/received_events","type":"User","site_admin":false},"created_at":"2016-04-23T02:39:20Z","updated_at":"2016-04-23T02:39:20Z","body":"Hmm, not sure, you on tmux? If so, do you still have the issue when you set `FZF_TMUX` to `0`?\r\n\r\nBy the way, I'm not sure if we can continue supporting cygwin, since the go version does not compile on it."}}