New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swiper takes over a second to start on very long files #416
Comments
|
Swiper traverses the whole buffer to collect the lines. This can be a lengthy operation for large buffers. However, having just tested org.el (25k lines), it takes < 0.5s to start up. Another known issue is with I suggest trying with minimal config - 2s sounds way too long for 11k lines. Perhaps also try |
Or maybe my laptop is just slower than yours. :-) Anyway, I've only just enabled swiper. I'll just keep using it for now and Thanks for the package On Fri, Mar 4, 2016 at 5:01 AM Oleh Krehel notifications@github.com wrote:
|
|
Something else is also a factor. It takes >2 secs on paradox-list-packages buffer, and there's only ~4200 lines. It also looses the font-lock coloring, which it doesn't for a regular php-mode buffer, so maybe there's a relation there. |
|
I have the same issue with several of my large Org-mode files. On my 💻 intel i5 with GNU Emacs 24.4.1 on Debian GNU/Linux and swiper-20160124.429 (from elpa):
So on my side, it is clearly not a second as mentioned in the title of this issue. It's so slow, that it's basically useless to me. 😦 However, I do like Swiper very much. Therefore, as a workaround, I plan to switch my search method according to the number of lines of the current buffer. As an Elisp amateur, I let you know when I've got something working here. Best case - of course - would be to find the reason for this performance lag. To shed some objective light on this issue, I did a profiler report for the time between invoking Swiper and the display of the search buffer before I start typing my search query:
So, Let me know when I can help you finding more information on this issue. Thanks for your great work! 👍 |
|
See the function from my config. It combines the best for (global-set-key "\C-s" 'ora-swiper)
(defun ora-swiper ()
(interactive)
(if (and (buffer-file-name)
(not (ignore-errors
(file-remote-p (buffer-file-name))))
(if (eq major-mode 'org-mode)
(> (buffer-size) 60000)
(> (buffer-size) 300000)))
(progn
(save-buffer)
(counsel-grep))
(swiper--ivy (swiper--candidates))))I've been using it for weeks now, it's really convenient. The start-up time for For a 60MB file consisting of
So I suggest you try the code above, let me know how it goes.
You're welcome, of course. I'm glad people like it. |
|
Thanks for the ultra-fast response! I do get issues with your code snippet though:
Remark: "I found #404" is really funny - pun not indented. |
|
Looks like you're using an outdated version of I'll try to release 0.8.0 in GELPA sometime this month. Can't have a 4 month out of date version around. |
|
To my astonishment, I figured out that due to a misconfiguration I had very old packages all over. So after a long sessions of upgrading all packages, I summarized my today's journey on my blog. Thanks for your great help! |
|
Thanks for the custom function, really awesome. |
This helps speed up searching in large files. Taken directly from: abo-abo/swiper#416 (comment) http://karl-voit.at/2016/04/09/chosing-emacs-search-method/
|
To wrap this up, the new function |
|
I'm no coder therefore this might be nonsense but wouldn't it be possible to show swiper input line directly while results are loaded asynchronously in the background? |
|
Same for me: with ~2k lines – ~3 seconds delay. But I use |
|
@Pitometsu Like it says above, |
|
@abo-abo what if the buffer is not a file? It is also taking me like 2 seconds when I try to do a search on |
|
Here's what I get in the package buffer (4143 lines): 0.5s start-up time is bearable to me. PRs to improve the speed of |
|
Maybe the line number calculation can be made configurable so that it could be disabled for better performance. |
|
Having investigated it a bit further, it seems So only twice as fast start-up. Not good enough to be worth the effort, especially considering the there are bigger buffers. Here's my draft implementation of an async swiper, if anyone wants to try it: (defun ivy-isearch-function (s)
(when (> (length s) 0)
(let ((re (setq ivy--old-re (ivy--regex-plus s)))
res)
(with-ivy-window
(goto-char (point-min))
(while (re-search-forward re nil t)
(push
(propertize
(buffer-substring-no-properties
(line-beginning-position)
(line-end-position))
'pos (match-end 0))
res))
(nreverse res)))))
(defun ivy-isearch-action (x)
(let ((pt (and x (get-text-property 0 'pos x))))
(when pt
(goto-char pt))))
(defun ivy--isearch-update-input ()
(when ivy--old-re
(swiper--cleanup)
(with-ivy-window
(ivy-isearch-action (ivy-state-current ivy-last))
(swiper--add-overlays
ivy--old-re
(window-start)
(window-end (selected-window) t)))))
(defun ivy-isearch ()
(interactive)
(ivy-read "Swiper: " #'ivy-isearch-function
:dynamic-collection t
:action #'ivy-isearch-action
:update-fn #'ivy--isearch-update-input
:unwind #'swiper--cleanup
:preselect (buffer-substring-no-properties
(line-beginning-position)
(line-end-position))))It still needs some refinement. |
Will you refine |
I'll look into refining it at some point. Right now I have a backlog of 90 unread open issues. |
|
Hi, |
|
@otadmor Well done. The fuzzy search didn't yet work for me. In one test example, an Org file with 5292 lines, the performance is much slower than |
|
Thanks. |
|
Ivy, ignore order and fuzzy (after the \n fix) re-builder are working. I also added a plain text and regularexpression re-builders. I run ivy-rotate-preferred-builders to switch between the re builders. If someone has a file which makes it slow ill be glad to debug it and fix. |
|
I have updated swiper-async to decide when to use grep (similar to counsel-grep-or-swiper). The difference is it does not saves the buffer if it different from the file and fallback to search-forward, supports "online" updating of the buffer while using swiper-async (fallback to the search-forward) and fallback to ivy-filter when there are atleast 3 chars in the input. |
|
Just for reference, this issue is solved by using |
|
See #2390 (comment) and #1908. In short, my proposal is to teach |
This happens before I even start to type anything. Everytime I invoke swiper on a very large file (11k lines), it takes about 2 seconds to until the prompt shows up.
Maybe you're already aware of this. And maybe it's not something you can fix. But I just thought I'd let you know.
The text was updated successfully, but these errors were encountered: