Recent

Author Topic: Slow editor on Mac  (Read 42155 times)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Slow editor on Mac
« on: February 03, 2014, 02:21:02 pm »
Started as reply to:
http://forum.lazarus.freepascal.org/index.php/topic,23238.msg140277.html#msg140277

Quote
2. One of the (almost) show stoppers for Lazarus in Mac Os is the terrible slowness of the Source Editor. At least in my dual core MacBook.
I thought that this would be fixed in RC2 but this behavior still exists.

Well I am not aware, that his was reported by anyone. So there is (was) no work/investigation into that.
And afaik, for many people this does no happen, for them it works fast.

Before going into details, there are 2 or 3 possibilities that come to mind first.

I assume a normal unit? few 100, maybe 3 or 4 thousand lines, of up to 1000 chars length.
Bigger should work too, I test with massive files sometimes, but lets start with that.

1)
 (probably not) scrolling. This would be, if only scrolling was slow, but nothing else.
In old days (0.9.28 or 0.926 even), scrolling would mean to print all the chars in the new position, instead of moving the existing bitmap.
But then typing would be fast.

2)
 font. Please try a different font or font size.

If your font is not strictly monospaced then the editor has to force it. This is more work. (though 40% cpu seems to high for this alone)Also on Mac,
(read notes at the end of post)

Some fonts use sub-pixels, which is not supported and leads to the same effect. For testing use a different font sizes.

Also ensure in the editor settings, page "editor/display", that the field "extra CHAR spacing" is set to 0. Any other value causes the same effect.

3)
 too much repaint....
Can you disable the following 2 settings, and retry please. Page "editor/display":
- "Show overview Gutter"
- "Show Class/Proc Hint"

4)
 Any other IDE operation.
Open a none-pascal/plain text file, and see if there is a difference.
Or put SynEdit (if you want with pas HL) on a Form, and run this (if you copy and paste text, then you need no file loading, no code of your own)

5)
How much is it affected by the size of the window? Is the dependency "linear" ?
e.g. editor shows only 2, 10, 20, 40  lines, (always the same length)
Does the cpu go like 2%, 10%, 20%, 40% ?

-----------------
About "2 font"

- Re-compile the IDE with SYNFONTDEBUG defined  (  -dSYNFONTDEBUG ),
- Then start it from console, with a logfile:
  In a  shell:
  /path/to/lazarus/lazarus.app/Contents/MacOS/lazarus --debug-log=/path/to/yourfiles/laz.log

Check for lines, like:
Code: [Select]
Final result for FONT  Width=xxx  Overhang=xxx  eto=BOOL
If eto is FALSE, (for the font, that you use / see name) then all is good. If it is true, then the extra work happens.


About "3 too much repaint"
- Re-compile the IDE with SYNSCROLLDEBUG defined  (  -dSYNSCROLLDEBUG ) Can be done together with the above)
- Then start it from console, with a logfile

Look for the lines that say
PAINT SynEdit123 0x200000 sfHasScrolled=BOOL rect=(10,5,200,100)

- If you edit a line, the high of the rect(last minus 2nd figure / 100-5 = 95) should be 1 or 2 lines only.
- Note you may get a 2nd paint of 40 to 60 pixel width all to the right rect=(500, Y, 550, Y2)

------
Additionally, to make sure nothing else of unexpected nature happen, you might want to compile with:
SynCheckPaintLock
AssertSynMemIndex
SynAssert
SynAssertFold

Those cause Exceptions, if  things go wrong, so you will notice.
And add -Criot too



VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Slow editor on Mac
« Reply #1 on: February 03, 2014, 03:10:33 pm »
I use Lazarus 90% of the time on Mac, with debugging and compiling on Windows XT and Ubuntu. I run it on three Macs, two desktops and one MacBook Pro. Mostly OS X 10.6.8, but also 10.8.5. Lazaus 1.0.14 at the moment.

I have not noticed anything unusual about the editor. Martin will know better, but perhaps a clean reinstall might help?

Cheers,
Frederick

Edit:
The MacBook Pro is 2.7 GHz Intel Core i7 with 4 GB RAM.

Sorry, I may be off topic, I have not yet tried RC2. :(
I'll give it a try and report back.
« Last Edit: February 03, 2014, 03:28:02 pm by Frederick »
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Slow editor on Mac
« Reply #2 on: February 03, 2014, 04:31:48 pm »
Just installed RC2 on OS 10.6.8 and compiled a couple of big projects. No obvious problems, and nothing noticeably slow about the editor.

Cheers,
Frederick
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: Slow editor on Mac
« Reply #3 on: February 03, 2014, 04:52:54 pm »
@Frederick

How about, if you set "Extra Char Spacing" to 1 ?

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Slow editor on Mac
« Reply #4 on: February 03, 2014, 05:12:41 pm »
Maybe (?) a bit slower with Extra char spacing = 1, but really hard to notice any diference.

Not sure why I would want that, but it seems to work ok. I use Andale Mono font by the way.

Cheers,
Frederick
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

Hoch

  • New Member
  • *
  • Posts: 35
Re: Slow editor on Mac
« Reply #5 on: February 03, 2014, 06:42:48 pm »
@Marti_Fr,

Wow! Great post! Lot's of homework!  :)

I've used the Lazarus Windows version and was impressed by it's lightness and performance compared to Delphi.

On the Mac, which is my main computer, I've been experiencing choppy editing (High cpu usage) since version 0.9.

If I'm the only one, there's probably something wrong with my editor settings. Maybe an old pref/config file?

Anyway, I will try what you suggest and report back.

Thanks a lot! :)

Hoch.

Hoch

  • New Member
  • *
  • Posts: 35
Re: Slow editor on Mac
« Reply #6 on: February 03, 2014, 07:03:11 pm »
@Martin_Fr,

This is what I found:

CPU Usage goes up to 40% on a unit of about 800 lines and 20% on a program file of 27 lines. So length matters... But code length is not the problem!

The CPU goes up *when I'm seeing the cursor*. If I scroll up or down with the scroll bar, so I do not see the cursor, the CPU usage drops to 0.

If I click to reposition the cursor in the new section of the code I'm watching, CPU goes up again.

Anyone can reproduce this?

Thanks! :)

Hoch.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: Slow editor on Mac
« Reply #7 on: February 03, 2014, 07:09:33 pm »
If you do the log, please also add: -dSynCaretDebug

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: Slow editor on Mac
« Reply #8 on: February 03, 2014, 07:16:35 pm »

CPU Usage goes up to 40% on a unit of about 800 lines and 20% on a program file of 27 lines. So length matters... But code length is not the problem!

That is also odd. Especially since I can not see how that relates to the caret.
Can you attach or mail your EditorOptions.xml please?

I tested Code here with 300 thousand lines, and no problems, except:
- Select all, and perform indent / unindent => DO not do that with more than 20 thousand lines. That does work in trunk. (1.3)
- replace all for a search term that appears 100000 times. Again better in trunk.
- anything with several lines of more than 100 thousand chars in one line, starts slowing down

Not scenarios that are very common.

-----------------------
Does the option "allow caret past end of line" make a difference? (Settings, Editor/ General)

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: Slow editor on Mac
« Reply #9 on: February 03, 2014, 07:17:45 pm »
Even on a 12 years old eMac with 700 MHz PPC processor I didn't perceive the editor to be slow.
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

VTwin

  • Hero Member
  • *****
  • Posts: 1215
  • Former Turbo Pascal 3 user
Re: Slow editor on Mac
« Reply #10 on: February 03, 2014, 07:22:13 pm »
I can easily get the %CPU above 50, even 70, by scrolling rapidly. I can't confirm a connection with the cursor though. However, I never noticed the editor being choppy, so have had no concern about it. 
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.6 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.6 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.6 (64 bit on VBox)

Hoch

  • New Member
  • *
  • Posts: 35
Re: Slow editor on Mac
« Reply #11 on: February 03, 2014, 07:53:16 pm »
@Martin_Fr,

Testing on a unit with 758 lines:

1) Scrolling with the scroll bar slider's is pretty slow and a bit jumpy. My mouse pointer is always faster than the slider, unless I scroll really slow. When doing normal scroll (not too fast or slow) CPU usage goes up 80%

2) When seeing the cursor, switching from Monaco 13 antialiased to Andale Mono antialiased makes things a bit worse. CPU goes up more or less 5%.

NOTE: Disabling antialiasing *reduced the CPU usage from 40% to 20%* (average). But Monaco, 13 looks too ugly...

3) Disabling those two options didn't do much difference

4) Opening a text file of 370 lines had the same effect as with a pascal file. When I see the cursor, CPU usage goes up. When I scroll or resize the window so I don't see the cursor, CPU usage goes down to 0.

5) Size of the window affects CPU usage if the cursor is visible. If I make the window bigger, CPU usage goes up. If I make it smaller, it goes down.
*If I resize so the cursor gets hidden, CPU usage goes to 0*.

By the way if I have two docs opened, I select the second one and I make the window very thin so the editor can't show the doc tab, Lazarus hides the second tab and switches automatically to the first document instead of keeping the second document visible.

Seeing the cursor or hiding it from view, makes all the difference.

Thanks and greetings! :)

Hoch.

Hoch

  • New Member
  • *
  • Posts: 35
Re: Slow editor on Mac
« Reply #12 on: February 03, 2014, 08:02:47 pm »
@Martin_fr,

I append my EditorOptions.xml

Thanks and greetings! :)

Hoch

Hoch

  • New Member
  • *
  • Posts: 35
Re: Slow editor on Mac
« Reply #13 on: February 03, 2014, 08:17:23 pm »
@Martin_fr,

I found the problem with code indent. Indent was set to 0 spaces/tabs in my prefs.

If this is default, then no problem, if not, I've never touched this option so I probably suffer from a bad/old EditorOptions.xml file.

How can I reset this file?

Thanks! :)

Hoch.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: Slow editor on Mac
« Reply #14 on: February 03, 2014, 08:34:05 pm »
If you delete the file (while the IDE is closed), a new one should be created automatically.

IIRC default is 2 spaces.

--------
About the PageControl tabs. After I found that "thin" means reduce width, not height, yes that is reproducible.

It should be reported on the bug tracker.
(Sorry, I do not maintain the carbon page control, so I cant help with this)


--------
About the speed. My bes guess is that something causes lots of repaints.

Can you try: open SynEdit.pp go to line 3688, that is inside
procedure TCustomSynEdit.Paint;

Code: [Select]
  FScreenCaret.Hide;

Comment that line.

Note, you may (or may not) get ghost images (left overs) of the caret, when you navigate

 

TinyPortal © 2005-2018