sequelpro icon indicating copy to clipboard operation
sequelpro copied to clipboard

Query Editor really slow on Macbook Pro with Touch Bar

Open andrewjurgenson opened this issue 8 years ago • 33 comments

I've got a query editor with about 100 lines of SQL in it. If I'm typing at the end of that sql - on line 100 - I get a normal response time to key strokes. If I move the cursor to line 1 and try typing there the typing goes at about 1 character per second. More lines = slower performance at the top of the file and it gradually improves as I move down the file. It makes the query editor very hard to use.

I've tried clearing the history, reinstalled Sequel Pro, restarted the computer, turned off all the query editor settings in preferences and none of that makes a difference.

I'm using a 2 week old MacBook Pro (13-inch, 2016, Four Thunderbolt 3 Ports) running Sierra. I migrated to this from an early 2015 MacBookPro running El Capitan and that did not have a problem.

Any suggestions would be greatly appreciated, thanks

andrewjurgenson avatar May 11 '17 02:05 andrewjurgenson

as an update - when using the query editor Sequel Pro is hitting 99.9% of CPU and the mono-sgen process goes to > 100%.

Similarly I loaded a 1000 line file and scrolling around it becomes very jerky and unusable - again it depends on cursor placement. If the cursor is at the bottom of the editor it's fine, if it's at the top it's very bad.

andrewjurgenson avatar May 15 '17 15:05 andrewjurgenson

I've found a partial solution to this. Performance of the query editor can be greatly improved by switching the font from Monaco to Menlo. It's still a little laggy at times, but it's much better

I also noticed that this is a duplicate of issue 2621 https://github.com/sequelpro/sequelpro/issues/2621

andrewjurgenson avatar May 16 '17 15:05 andrewjurgenson

Well, you said you didn't have the problem under 10.11 and the poster in #2621 says he had the issue on both, 10.11 and 10.12.

dmoagx avatar May 16 '17 21:05 dmoagx

True. There does seem to be more to it though than the OS version. I've tried it on 3 machines in our office: late 2016 Macbook Pro running Sierra : problem early 2015 Macbook Pro running El Capitan: no problem early 2015 Macbook Pro running Sierra: no problem mid 2011 iMac running Sierra: no problem

andrewjurgenson avatar May 16 '17 22:05 andrewjurgenson

On the machine with a problem, can you create a new user account and try it with that?

dmoagx avatar May 16 '17 22:05 dmoagx

Done - the new user account exhibits the same problem.

andrewjurgenson avatar May 17 '17 21:05 andrewjurgenson

Experiencing the same behavior. MacOS 10.12.5, 15in 2016 MBPr, 2.6GHz i7, 16gb ram. Sequel Pro v1.1.2 build 4541.

Editor with ~200 lines. If I try typing on line 1, theres a 1 second delay between keystrokes, but typing at the end of the editor has almost no delay.

Idle CPU usage: ~5% typing at beginning: ~95-99% typing at end: ~10-20%

memory usages hovers around 250-350MB in all scenarios.

spantin avatar Jun 28 '17 21:06 spantin

Have you tried what was mentioned above?

Performance of the query editor can be greatly improved by switching the font from Monaco to Menlo.

250-350 MiB is quite a lot of memory. Did you have > 10 connections open at that time? Also, possibly, you have a rather large query in your query history; try clearing that.

You can try to put Sequel Pro and Activity Monitor side by side, select SP in Activity Monitor and press alt+cmd+S (Sample process) and immediately switch to Sequel Pro and start typing where it is supposed to be slow (until sampling ends). Afterwards post the results of sampling.

dmoagx avatar Jun 29 '17 20:06 dmoagx

I've attached a sample as requested. I note that my SP was running at 440Mb with 4 connections open and 550Mb+ with 6 connections.

Sequel_Pro_sampling.txt

andrewjurgenson avatar Jul 06 '17 20:07 andrewjurgenson

Thanks, this sample shows one very interesting thing I hadn't thought about before: You are using a touchbar Mac and a significant amount of time in the sample goes to touchbar stuff.

But, since I don't have that fancy stuff I won't likely be able to reproduce it.

dmoagx avatar Jul 06 '17 21:07 dmoagx

The irony for me is that I almost always use the laptop in Clamshell mode so I don't even have access to the touchbar.

andrewjurgenson avatar Jul 06 '17 22:07 andrewjurgenson

I just tried https://red-sweater.com/touche/ and with that I'm also able to reproduce the issue.

It seems there are other people also affected by this: http://support.hogbaysoftware.com/t/laggy-ui-on-macbook-pro-15-inch-2016/2809/13 - I wonder what they changed.

dmoagx avatar Jul 06 '17 22:07 dmoagx

Some quick testing shows that the expensive -[NSLayoutManager(NSPrivate) _fillLayoutHoleForCharacterRange:desiredNumberOfLines:isSoft:] method is usually called once for each character typed, but in Sequel Pro (on Sierra) it is called 65 times for a single character.

dmoagx avatar Jul 07 '17 02:07 dmoagx

Interesting. Thanks for digging into it.

andrewjurgenson avatar Jul 07 '17 14:07 andrewjurgenson

I moved the SPTextView class to a simple test app and debugging showed that the NSMutableAttributedStringAddAttributeValueRange() calls in -[SPTextView doSyntaxHighlighting are what is triggering the slowness.

But...for some very odd reason when disabling "Uses: Font Panel" in Interface Builder, it starts working fine again.

This seems to be caused by -[NSTextView rangesForUserCharacterAttributeChange] which is called internally by macOS and which is documented as:

For plain text the range is the entire contents of the receiver. Returns nil if the receiver isn’t editable or doesn’t use the Font panel.

Apple then uses that range to call -[NSAttributedString enumerateAttributesInRange:options:usingBlock:] which invokes block each time the style attributes change (e.g. 400 times in a 2100 character SQL string) and ends up calling -[NSFontManager convertFont:toHaveTrait:] each time (which is extremely expensive for some fonts, e.g. Monaco, while working fine for others, e.g. Menlo).

I still don't know what Apple is trying to achieve here regarding the touch bar, but it seems like they forgot that a plain text NSTextView can still have different text styles applied.

dmoagx avatar Jul 16 '17 19:07 dmoagx

Does that mean that it requires Apple to make fix before this will work properly?

andrewjurgenson avatar Jul 20 '17 14:07 andrewjurgenson

IMHO yes, but if I were to file a bug with them about this it would usually take 6-24 months for their initial response and another 10 months to fix it (should they decide to feel responsible and are not already aware of it). Talking to Apple is pretty much a dead end unless you pay them some hundred dollars for per-incident support and even then there is no guarantee that they can actually help with the issue...

So basically we have to think about a different solution. For the moment you should change the font of the query editor to Menlo as that seems to cause less problems.

Another option may be to disable Touch Bar for Sequel Pro by going to System Prefs > Keyboard > Shortcuts > Function Keys and adding Sequel Pro there.

dmoagx avatar Jul 20 '17 15:07 dmoagx

FWIW, switching the touch bar to always show function keys for Sequel Pro didn't seem to make a difference for me. Switching to Menlo does seem to help a little, but not completely.

The symptoms I'm experiencing are pretty much the same as the OP - if a lot of text is in the editor window, it's extremely responsive when typing at the bottom of the editor window, and gets less responsive the further up the content I scroll.

aripringle avatar Aug 08 '17 21:08 aripringle

+1 on this issue. Switching to Menlo helps a bit, disabling touchbar does not help at all.

optikalefx avatar Jun 24 '18 23:06 optikalefx

+1 as well. Just got the new macbook pro with touchbar, and the query editer is now unusable 😔. Anyone have any other potential work-arounds for this?

atopiler avatar Jul 31 '18 17:07 atopiler

+1 here... Thanks for digging in to this and finding at least partial solutions (Menlo).

rbalslev avatar Sep 06 '18 09:09 rbalslev

+1 on this. Switching to Menlo does help a bit, but not much.

cquinn96 avatar Sep 30 '18 14:09 cquinn96

on Mojave, even switching to menlo now has no impact 😔

atopiler avatar Oct 13 '18 01:10 atopiler

+1 on this changing the font to menlo improved a bit, but slowness is huge

pedrobomente avatar Oct 25 '18 15:10 pedrobomente

I disable all the "helpful" options in the Query Editor preferences pane. "Highlight current query" in particular really slows things down for me and adds nothing of value. Now things are pretty snappy even with several hundred lines.

We really need the ability to disable syntax highlighting as well, that should speed things up a lot.

krozett avatar Feb 06 '19 22:02 krozett

+1 just got a touchbar and I use Query Editor all day. This is killing me.

gregorydickson avatar Feb 28 '19 22:02 gregorydickson

Same issue on 10.13.6 MacBookPro15,1 (touchbar) Once the query editor reaches ~100 lines, the slowness begins. Switching fonts improved it.

mcauser avatar Mar 01 '19 04:03 mcauser

Same issue on 2018 MacBook Pro 15" with Touchbar on Mojave.

Switching to Menlo helps a bit but again not much.

rajbdilip avatar Mar 01 '19 04:03 rajbdilip

+1 Very frustratin, no touchbar here, same experience, changinf the font helps but it's minor

EarthmanWeb avatar Mar 25 '19 11:03 EarthmanWeb

I can confirm that turning off all typing assistance preferences for the query window and switching to Menlo has greatly improved performance. Never really needed those preferences anyway, so I'm happy for now.

I'm on a 2018 Macbook with touchbar Mojave

Maccxx avatar Apr 22 '19 15:04 Maccxx