Closed jdavisclark closed 8 years ago
For reference, the marker views are currently in this repo: https://github.com/atom/find-and-replace/blob/master/lib/marker-view.coffee At some point, we intend them to go in core so other packages can use them, but for now, they are in here.
The slow parts:
TextBuffer::positionForCharacterIndex()
: https://github.com/atom/text-buffer/blob/master/src/text-buffer.coffee#L480 by way of SpanSkipList:totalTo
: https://github.com/atom/span-skip-list/blob/master/src/span-skip-list.coffee#L22EditorView::pixelPositionForScreenPosition(...)
. Though this isnt terribly slow right now.If someone feels the itch, I would start by profiling. Search for a space in a long text.
I feel like this is @nathansobo territory.
I wonder if we should support maintaining a cursor in the SpanSkipList
for big scans like this. That way we wouldn't need to scan from the beginning every single time. It would be nice to see the profile beneath ::totalTo
to get a sense of anything simple we could optimize there.
I wonder if the subscription stuff is lowest hanging fruit. I'm surprised all the eventing stuff is in that profile. That anon function above program
is also all subscription stuff. Each MarkerView subscribes to 3 events on the marker, and one on the editor. What if someObject (find model?) could subscribe to all events for all search-result
markers, then delegate to the marker view?
Also, what's creating all the garbage? I guess a heap profile would be in order. Probably more than just dom elements.
Marker views really need to go into core so we can optimize this stuff once.
I'm working with a 22k LOC CoffeeScript file. Every time I want to search for, lets say, 'cucumber' - quotes included - Atom tries to match the first single quote before I can even type the next characters, and locks completely.
Maybe introduce a slight delay between typing and starting the search?
Well, maybe the real problem here is having 22k lines of CoffeeScript :scream:
There is a delay, it's just not very long (300ms?).
I couldn't find where the delay is set... Another solution would be to bring back the search after 1st char behavior. It improves the experience when editing large files, and searching for just one char can still be achieved by core:confirm
Try a regex find in Android WebView.java with /*
: Atom freezes.
Replacing [tab] characters for double [blank-space] on >3000 matches makes the software to freeze and throw "keep waiting" confirmations like 3 times 'till its done.
I think the best solution (at least as a stopgap) is to offload processing to another process, so at least the UI is unblocked while finding happens.
I also noticed if you searched something with RegEx (e.g. /,(\n+\t*)/, which were very slow, single core 100% usage) and stop searching -> leave search "pattern" in search filed but closes the search view by pressing "Escape", its still slow, because it feels like its still searching the pattern after every content change. So when i open the search view again and disable the RegEx option and empty the search pattern and close it via "Escape" too, same as before. It runes fine/smooth.
Another thing i noticed is if you use the RegEx example about and replace the first line its fast, second slower, third slower as second, after the 7-10 replacement it will take about 10-30 sec to proceed 1 line replacement.
Tested in atom 0.174 on Ubuntu 14.04 (Linux **** 3.13.0-44-generic #73-Ubuntu SMP Tue Dec 16 00:22:43 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux) with a perl module (.pm) about 760 lines
I could test this on windows too if desired
For this file https://gist.github.com/Cipa/62e40f9ac95d65ddcadd I tried to remove the empty lines with find/replace(I just copied the empty space between 2 lines and tried to replace it with nothing) and currently I am at the 4th Keep Waiting message and it still did not do it. I think it crashed.
Same thing takes 5 seconds or less in Coda.
Atom 0.179.0, started in safe mode
Thanks for the test case. Sorry it's slow :(
Today i replaced a file with 15k lines all step by step (not replace all), and i noticed the first time i opened the file in atom i could nearly instand replace line step by step, after about 200 lines it getting slow (800ms/line). So i closed the file and reopened it (same atom session/window), it the time decreases to ~150ms foreach line, after some replacements (~200) it increases to ~2sec. 3., 4. ... same behaviour as the second opening, same times no time increasing.
I used this RegEx ,(((?:\s+--.*)?\r?\n)+\s+)+
with folling in replacement $1,
, only the RegEx option were enabled.
Tested in 0.194.0 on linux same as my comment above, i hope this information help in someway.
This is the reason I don't use Atom as my main text editor. I want to spend time coding, not waiting for a tool. When I get some free time I will look into the possibility of using https://github.com/ggreer/the_silver_searcher as the backend and building an Atom plugin similar to https://github.com/rking/ag.vim
@willopez what specifically is slow for you? Is it search in buffer? In project? What are you searching for?
+1 on the silver searcher.
Search in general on a smaller file takes a fair amount of time. Doesn't matter how many files are included in the project. I have a 30kb json file, replacing the 3000 quotes to double quotes took about 45 seconds time to do.
@railrhoad thats the exact type of thing I use it for a lot in other editors
@nathansobo awesome news with the marker performance! cant wait.
@jdc0589 It's worth noting that creating markers could still use some optimization. But once they're on screen life should be much better. Stay tuned.
I would like to add another performance issue to the discussion. When you work on several files at once (which we do all the time) and you're in a file and search for something but then switch back to another file without closing the search first, it will automatically also search the file you went back to or any newly opened file. I always leave the search bar open after I've searched for something and of course I'm glad it doesn't close automatically when you change to another file. But please, add a settings function to disable auto searching everytime you switch between files or open a new one.
My editor also reports to keep on hanging when performing the regex
\\n
I need to replace all \n
with actual endline characters. This regex on a file with 2900 matches found is currently taking a couple of minutes before finishing.
This has been improved significantly via a new marker index which is currently in master. Check out these PRs for more information
As with any performance things, more work can always be done, and we have ideas. We will create more specific issues moving forward.
thanks a bunch @benogle! I've actually been using atom some more recently (as my preferred markdown editor) and have noticed some solid marker improvements.
there are some pretty serious issues with find/replace performance. I realize that some of this is an issue with speeding up marker displays in Atom core (and is supposedly already logged in the closed issue tracker), but i wanted to make sure there was a public issue as well.
e. g. stripping newlines in a ~300 line file via
Find: "\r|\n"
andReplace:""
can easily take over 10 seconds.