Scintilla buffered drawing - Is it needed?



  • Hello all,

    Here is an excerpt from the Scintilla documentation:

    SCI_SETBUFFEREDDRAW(bool buffered)
    SCI_GETBUFFEREDDRAW → bool
    These messages turn buffered drawing on or off and report the buffered drawing state. Buffered drawing draws each line into a bitmap rather than directly to the screen and then copies the bitmap to the screen. This avoids flickering although it does take longer. The default is for drawing to be buffered on Win32 and GTK+ and to not be buffered on Cocoa and Qt. Buffered drawing is not supported on Cocoa.

    Current platforms perform window buffering so it is almost always better for this option to be turned off. For Win32 and GTK+, client code should turn off buffering at initialisation. There are some older platforms and unusual modes where buffering may still be useful.

    Scintilla views in Notepad++ currently report to be using buffered drawing.
    My question is: Is that really needed? The Sci documentation suggests to “turn off buffering at initialization” for Win32 so perhaps at Notepad++ initialization the buffering should be turned off.

    BR



  • @pnedev
    I tried to find some infos on the web to understand what’s going on and
    this site http://www.tomshardware.com/reviews/2d-windows-gdi,2547-3.html
    seems to come to the same conclusion as the scintilla statement.
    Then I tried to see if this has really impact in terms of performance so I
    profiled my python lexer on fairly large code and here are the results.

    editor.setBufferedDraw(False)
    
    
    
             86 function calls in 0.018 seconds
    
       Ordered by: standard name
    
       ncalls  tottime  percall  cumtime  percall filename:lineno(function)
            4    0.000    0.000    0.000    0.000 :0(append)
           25    0.000    0.000    0.000    0.000 :0(find)
           19    0.000    0.000    0.000    0.000 :0(isspace)
            1    0.000    0.000    0.000    0.000 :0(setprofile)
            1    0.001    0.001    0.017    0.017 <string>:1(<module>)
            1    0.009    0.009    0.016    0.016 custom_lexer.py:164(custom_folding_routine)
           30    0.007    0.000    0.007    0.000 custom_lexer.py:166(do_folding_regex)
            4    0.000    0.000    0.000    0.000 custom_lexer.py:168(<lambda>)
            1    0.000    0.000    0.018    0.018 profile:0(custom_folding_routine(0, 448); print)
            0    0.000             0.000          profile:0(profiler)
    
    
             36013 function calls in 3.384 seconds
    
       Ordered by: standard name
    
       ncalls  tottime  percall  cumtime  percall filename:lineno(function)
         1405    0.002    0.000    0.002    0.000 :0(append)
        10805    0.027    0.000    0.027    0.000 :0(find)
         7287    0.013    0.000    0.013    0.000 :0(isspace)
            1    0.000    0.000    0.000    0.000 :0(setprofile)
            1    0.001    0.001    3.384    3.384 <string>:1(<module>)
            1    1.657    1.657    3.383    3.383 custom_lexer.py:164(custom_folding_routine)
        15107    1.676    0.000    1.686    0.000 custom_lexer.py:166(do_folding_regex)
         1405    0.008    0.000    0.010    0.000 custom_lexer.py:168(<lambda>)
            1    0.000    0.000    3.384    3.384 profile:0(custom_folding_routine(448, 139838); print)
            0    0.000             0.000          profile:0(profiler)
    
    
    # -----------------------------------------------------------------------------
    
    editor.setBufferedDraw(True)
    
             86 function calls in 0.018 seconds
    
       Ordered by: standard name
    
       ncalls  tottime  percall  cumtime  percall filename:lineno(function)
            4    0.000    0.000    0.000    0.000 :0(append)
           25    0.000    0.000    0.000    0.000 :0(find)
           19    0.000    0.000    0.000    0.000 :0(isspace)
            1    0.000    0.000    0.000    0.000 :0(setprofile)
            1    0.001    0.001    0.018    0.018 <string>:1(<module>)
            1    0.009    0.009    0.017    0.017 custom_lexer.py:164(custom_folding_routine)
           30    0.007    0.000    0.007    0.000 custom_lexer.py:166(do_folding_regex)
            4    0.000    0.000    0.000    0.000 custom_lexer.py:168(<lambda>)
            1    0.000    0.000    0.018    0.018 profile:0(custom_folding_routine(0, 448); print)
            0    0.000             0.000          profile:0(profiler)
    
    
             36013 function calls in 3.452 seconds
    
       Ordered by: standard name
    
       ncalls  tottime  percall  cumtime  percall filename:lineno(function)
         1405    0.002    0.000    0.002    0.000 :0(append)
        10805    0.032    0.000    0.032    0.000 :0(find)
         7287    0.012    0.000    0.012    0.000 :0(isspace)
            1    0.000    0.000    0.000    0.000 :0(setprofile)
            1    0.001    0.001    3.452    3.452 <string>:1(<module>)
            1    1.725    1.725    3.450    3.450 custom_lexer.py:164(custom_folding_routine)
        15107    1.670    0.000    1.681    0.000 custom_lexer.py:166(do_folding_regex)
         1405    0.008    0.000    0.011    0.000 custom_lexer.py:168(<lambda>)
            1    0.000    0.000    3.452    3.452 profile:0(custom_folding_routine(448, 139838); print)
            0    0.000             0.000          profile:0(profiler)
    

    The difference of 0,07 Seconds seems to be inisgnificant.
    If this is a valid test, not sure - still have the feeling that I haven’t understood completely.

    Cheers
    Claudia



  • @Claudia-Frank

    If this is a valid test, not sure

    AFAIK Scintilla does not redraw at all during lexing. I’m not sure of a good way to test this without profiling the actual Scintilla code.



  • Hi @Claudia-Frank ,

    Thanks for trying that. However I think @dail is right.
    IMO, we can just rely on the Scintilla documentation in this case.

    BR



  • Hello all,

    FYI, I tried disabling the Scintilla buffering and worked with N++ some time this way. In some occasions I observed flickering in the Sci view that was not present with buffering enabled. So it appears the buffering is actually necessary.
    Thanks.

    BR


Log in to reply