Recent

Author Topic: Question about fast SynEdit renderer  (Read 3512 times)

AlexTP

  • Hero Member
  • *****
  • Posts: 2386
    • UVviewsoft
Question about fast SynEdit renderer
« on: February 13, 2021, 03:02:09 pm »
Martin,
need some help to speedup ATSynEdit rendering.
ATSynEdit does this for each visible line:

- calculate array of colored 'tokens', e.g. in "func A(b)" we have tokens "func", "A", "(", "b", ")".
- loop over this array: for each item:

a) set font.style (italic, etc)
b) call ExtTextOut (or direct WinAPI call TextOut in win32)
c) apply underlines/waves/borders

But it's slow on gtk2! maybe because too many changes of font.style?
Why SynEdit is faster?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Question about fast SynEdit renderer
« Reply #1 on: February 13, 2021, 04:15:42 pm »
Good question.

First of all is it really the font style? What if you have changes only in color?

One possible issue: The "Eto" array. (the width for each char). Only specify it if needed. Gtk does not have it (and neither cocoa), and the emulation of it in the widgetset is probably not that fast.

You can find SynEdits output in unit LazSinTextArea. Search for fTextDrawer.NewTextOut

SynEdit tokenizer uses pchar, pointing into the original string. So less temp strings.
If you use actual strings, then make sure you test speed without heaptrc. HeapTrc slows down mem alloc, and each temp string, each resize of a string, .... is a mem(re)alloc.


also check
FTextDrawer.SetStyle unit SynTextDrawer

I havent looked at that in ages, but it seems to have a cache of fonts for the styles.

AlexTP

  • Hero Member
  • *****
  • Posts: 2386
    • UVviewsoft
Re: Question about fast SynEdit renderer
« Reply #2 on: February 20, 2021, 12:52:28 pm »
To find what part is slow, I made very tall window of CudaText (3--6 screen by height) and do stopping in IDE. I see that in 50% of cases I stop here...

Quote
#0 ?? at :0
#1 ?? at :0
#2 pango_itemize_with_base_dir at :0
#3 ?? at :0
#4 ?? at :0
#5 pango_renderer_draw_layout at :0
#6 gdk_draw_layout_with_colors at :0
#7 DRAWTEXTWITHCOLORS(0x7ffff5c79440, 0x7ffff50c7458 'compare_exchange_strong', 23, 260, 513, 0x0, 0x7ffff5c795a8) at gtk2/gtk2devicecontext.inc:1362
#8 DOTEXTOUT(0x7fffffffc450, 260, 513, 0x7ffff50c7458 'compare_exchange_strong', 23) at gtk2/gtk2winapi.inc:3841
#9 EXTTEXTOUT(0x7ffff6229f50, 140737316885568, 260, 513, 2, 0x7fffffffc5ec, 0x7ffff50c7458 'compare_exchange_strong', 23, 0x0) at gtk2/gtk2winapi.inc:3917
#10 EXTTEXTOUT(140737316885568, 260, 513, 2, 0x7fffffffc5ec, 0x7ffff50c7458 'compare_exchange_strong', 23, 0x0) at include/winapi.inc:282
#11 CANVASTEXTOUT(0x7ffff435c5e0, 71, 512, 0x7ffff5976af8 '    BOOST_FORCEINLINE boo'..., 0x7ffff5883bdc, 0, {EDITOR = 0x7ffff5883090, HASASCIINOTABS = true, SUPERFAST = false, TABHELPER = 0x7ffff58716e0, LINEINDEX = 220, CHARINDEXINLINE = 1, CHARSIZE = {X = 7, Y = 16}, CHARSSKIPPED = 0, TRIMMEDTRAILINGNONSPACES = false, DRAWEVENT = {Proc = {procedure (POINTER, TOBJECT, TCANVAS, LONGINT, LONGINT, LONGINT, UNICODESTRING, TPOINT, TATINTARRAY)} 0x7fffffffc7c0, Self = 0x7ffff587f050}, CONTROLWIDTH = 1038, TEXTOFFSETFROMLINE = 1, SHOWUNPRINTED = false, SHOWUNPRINTEDSPACESTRAILING = false, SHOWUNPRINTEDSPACESBOTHENDS = false, SHOWUNPRINTEDSPACESONLYINSELECTION = false, SHOWFONTLIGATURES = true, COLORNORMALFONT = 2105376, COLORUNPRINTEDFONT = 10526904, COLORUNPRINTEDHEXFONT = 10789024, FONTNORMAL_NAME = 0x7ffff5a8c338 'DejaVu Sans Mono', FONTNORMAL_SIZE = 9, FONTITALIC_NAME = 0x0, FONTITALIC_SIZE = 9, FONTBOLD_NAME = 0x0, FONTBOLD_SIZE = 9, FONTBOLDITALIC_NAME = 0x0, FONTBOLDITALIC_SIZE = 9, DETECTISPOSSELECTED = {Proc = {function  (POINTER, LONGINT, LONGINT) : BOOLEAN} 0x7fffffffc7c0, Self = 0x7ffff5883090}}) at atsynedit_canvasproc.pas:879
#12 DOPAINTTEXTTO(0x7ffff5883090, 0x7ffff435c5e0, {LEFT = 71, TOP = 0, RIGHT = 1015, BOTTOM = 6330, TOPLEFT = {X = 71, Y = 0}, BOTTOMRIGHT = {X = 1015, Y = 6330}, VECTOR = {71, 0, 1015, 6330}}, {X = 7, Y = 16}, true, true, {VERTICAL = false, NMAX = 210, NPAGE = 134, NPOS = 0, NPOSLAST = 0, NPIXELOFFSET = 0, SMOOTHCHARSIZE = 7, SMOOTHMAX = 938, SMOOTHPAGE = 938, SMOOTHPOS = 0, SMOOTHPOSLAST = 0}, {VERTICAL = true, NMAX = 1647, NPAGE = 394, NPOS = 198, NPOSLAST = 1253, NPIXELOFFSET = 0, SMOOTHCHARSIZE = 16, SMOOTHMAX = 26352, SMOOTHPAGE = 6304, SMOOTHPOS = 3168, SMOOTHPOSLAST = 20048}, -1) at atsynedit.pas:3272
#13 DOPAINTMAINTO(0x7ffff5883090, 0x7ffff435c5e0, -1) at atsynedit.pas:2694
#14 DOPAINTALLTO(0x7ffff5883090, 0x7ffff435c5e0, -1) at atsynedit.pas:4672
#15 DOPAINT(0x7ffff5883090, -1) at atsynedit.pas:4698
#16 PAINTEX(0x7ffff5883090, -1) at atsynedit.pas:4800
#17 PAINT(0x7ffff5883090) at atsynedit.pas:4774
#18 PAINTWINDOW(0x7ffff5883090, 140737316870720) at include/customcontrol.inc:123
#19 PAINTHANDLER(0x7ffff5883090, {MSG = 15, UNUSEDMSG = 0, DC = 140737316870720, PAINTSTRUCT = 0x7ffff4213c40, RESULT = 0}) at include/wincontrol.inc:4873
#20 WMPAINT(0x7ffff5883090, {MSG = 15, UNUSEDMSG = 0, DC = 140737316870720, PAINTSTRUCT = 0x7ffff4213c40, RESULT = 0}) at include/wincontrol.inc:6836
#21 WMPAINT(0x7ffff5883090, {MSG = 15, UNUSEDMSG = 0, DC = 140737316870720, PAINTSTRUCT = 0x7ffff4213c40, RESULT = 0}) at include/customcontrol.inc:103


so it meas it is gtk2 code is slow and not LCL WS code but gtk2 function!
gdk_draw_layout_with_colors

I don't know how to speedup it

 

TinyPortal © 2005-2018