If 'all-completions' is called under certain conditions, case-fold-search is specbound and unbound for each matching candidate. Because this variable is DEFVAR_PER_BUFFER, specbinding it is slow (scales with number of buffers). This patch eliminates specbinding from the three core completion functions. Benchmark: (dotimes (i 300) (get-buffer-create (format " *test-buffer-%s*" i))) (let ((completion-regexp-list '("\\`.*?"))) (benchmark-run-compiled 50 (all-completions "" obarray #'boundp))) 9.9 seconds without patch, 0.83 seconds with patch applied. Note that for the performance issue to be observed, we must have a lot of live buffers, completion-regexp-list must be non-nil and a predicate must be passed to all-completions. The last two conditions are satisfied if we press M-x TAB.