Community
    • Login

    Freezing when pasting large amount of text between quotes or heredoc (language PHP)

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    12 Posts 4 Posters 263 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Min LiuM
      Min Liu @Alan Kilborn
      last edited by

      @Alan-Kilborn
      It hangs for a long time, and seems to increase exponentially with the number of lines.

      Notepad++ v8.9 (64-bit)
      Build time: Dec 27 2025 - 14:28:33
      Scintilla/Lexilla included: 5.5.8/5.4.6
      Boost Regex included: 1_85
      TinyXML-2 included: 11.0.0
      nlohmann JSON included: 3.12.0
      Path: C:\Program Files\Notepad++\notepad++.exe
      Command Line: “C:\inetpub\wwwroot\minzliu\test3.php”
      Admin mode: OFF
      Local Conf mode: OFF
      Cloud Config: OFF
      Periodic Backup: ON
      Placeholders: OFF
      Scintilla Rendering Mode: SC_TECHNOLOGY_DIRECTWRITE (1)
      Multi-instance Mode: monoInst
      asNotepad: OFF
      File Status Auto-Detection: cdEnabledNew (for current file/tab only)
      Dark Mode: OFF
      Display Info:
      primary monitor: 2560x1440, scaling 100%
      visible monitors count: 2
      installed Display Class adapters:
      0000: Description - Intel® UHD Graphics 770
      0000: DriverVersion - 32.0.101.7079
      0001: Description - Microsoft Remote Display Adapter
      0001: DriverVersion - 10.0.26100.7019
      0002: Description - Microsoft Remote Display Adapter
      0002: DriverVersion - 10.0.26100.3624
      0003: Description - Microsoft Remote Display Adapter
      0003: DriverVersion - 10.0.26100.3624
      - warning, search has been limited to maximum number of adapter records: 4
      OS Name: Windows 11 Pro (64-bit)
      OS Version: 25H2
      OS Build: 26200.7462
      Current ANSI codepage: 1252
      Plugins:
      mimeTools (3.1)
      NppConverter (4.7)
      NppExport (0.4)

      PeterJonesP mpheathM 2 Replies Last reply Reply Quote 1
      • PeterJonesP
        PeterJones @Min Liu
        last edited by PeterJones

        @Min-Liu ,

        I can confirm:

        • Create C:\usr\local\share\TempData\Npp\heredoc.php:
          <?php
          
          $a =<<< AAA
          
          AAA
          ?>
          
        • Create C:\usr\local\share\TempData\Npp\16k lines.txt: enter text AZAZAZAZ 123456789[NEWLINE] then Ctrl+A Ctrl+D until 16k lines, and save.

        For each listed below, Ctrl+A Ctrl+C to copy from 16k lines.txt and paste in the empty line between the two AAA lines of heredoc.php

        Search for change in behavior: use a fresh unzip (no additional plugins, etc)

        • SciTE 5.6.8 = near-instantaneous paste
        • v8.7 = near-instantaneous paste
        • v8.9 = more than a minute to paste: confirmed there’s a difference in behavior; see Resource Monitor CPU screenshot
        • v8.8 = >1min
        • v8.7.5 = near-instantaneous paste
        • v8.7.9 = >1min
        • v8.7.6 = >1min

        Debug info for the v8.7.5 (last fast), v8.7.6 (first slow), and v8.9 (showing it’s still a problem)

        v8.7.5 = Fast

        Notepad++ v8.7.5   (64-bit)
        Build time : Dec 21 2024 - 05:13:03
        Path : C:\usr\local\apps\npp\npp.8.7.5-php\notepad++.exe
        Command Line : 
        Admin mode : OFF
        Local Conf mode : ON
        Cloud Config : OFF
        Periodic Backup : ON
        Placeholders : OFF
        DirectWrite : ON
        Multi-instance Mode : monoInst
        File Status Auto-Detection : cdEnabledNew (for current file/tab only)
        Dark Mode : OFF
        OS Name : Windows 11 Home (64-bit)
        OS Version : 24H2
        OS Build : 26100.7171
        Current ANSI codepage : 1252
        Plugins : 
            mimeTools (3.1)
            NppConverter (4.6)
            NppExport (0.4)
        

        v8.7.6 = Slow

        Notepad++ v8.7.6   (64-bit)
        Build time : Jan 24 2025 - 08:27:33
        Path : C:\usr\local\apps\npp\npp.8.7.6-php\notepad++.exe
        Command Line : 
        Admin mode : OFF
        Local Conf mode : ON
        Cloud Config : OFF
        Periodic Backup : ON
        Placeholders : OFF
        DirectWrite : ON
        Multi-instance Mode : monoInst
        File Status Auto-Detection : cdEnabledNew (for current file/tab only)
        Dark Mode : OFF
        OS Name : Windows 11 Home (64-bit)
        OS Version : 24H2
        OS Build : 26100.7171
        Current ANSI codepage : 1252
        Plugins : 
            mimeTools (3.1)
            NppConverter (4.6)
            NppExport (0.4)
        

        v8.9 = Slow

        Notepad++ v8.9   (64-bit)
        Build time: Dec 27 2025 - 14:28:33
        Scintilla/Lexilla included: 5.5.8/5.4.6
        Boost Regex included: 1_85
        TinyXML-2 included: 11.0.0
        nlohmann JSON included: 3.12.0
        Path: C:\usr\local\apps\npp\npp.8.9-php\notepad++.exe
        Command Line: 
        Admin mode: OFF
        Local Conf mode: ON
        Cloud Config: OFF
        Periodic Backup: ON
        Placeholders: OFF
        Scintilla Rendering Mode: SC_TECHNOLOGY_DIRECTWRITE (1)
        Multi-instance Mode: monoInst
        asNotepad: OFF
        File Status Auto-Detection: cdEnabledNew (for current file/tab only)
        Dark Mode: OFF
        Display Info:
            primary monitor: 1920x1080, scaling 100%
            visible monitors count: 1
            installed Display Class adapters: 
                0000: Description - Intel(R) UHD Graphics 770
                0000: DriverVersion - 32.0.101.7026
        OS Name: Windows 11 Home (64-bit)
        OS Version: 24H2
        OS Build: 26100.7171
        Current ANSI codepage: 1252
        Plugins: 
            mimeTools (3.1)
            NppConverter (4.7)
            NppExport (0.4)
        

        update: oddly, I think that means that the “enhance performance of syntax highlighting for large files” fix in v8.7.6 might have slowed things down when pasting into the PHP heredoc…

        1 Reply Last reply Reply Quote 1
        • mpheathM
          mpheath @Min Liu
          last edited by

          @Min-Liu

          This is related to the change of idle styling. Note SCI_SETIDLESTYLING = 0 (default) to now = 3 in Notepad++.

          When the paste action occurs, 50,000 lines is styled before being shown which you regard the issue as being frozen with the Gui. The Gui is waiting for the styling to finish. If you interact with the Gui while the program is busy processing then the Gui will signal with not responding as the Gui message loop is not processing messages at that time. Takes about 30 seconds in my testing to style, though can take longer if you interact with the Gui too much to confuse it and make it worse. Switching tabs is just as tormenting as full restyling is requested.

          If you want the old “just in time” aka JIT with only what is visual processing behavior, then install LuaScript/PythonScript/… plugin and change the idle styling setting.

          PythonScript: editor.setIdleStyling(0)

          Lua: editor.IdleStyling = 0

          This might be enough in a startup script. If you want to manage it then this might Lua code help:

          local function ModIdleStyling(modType, _, length)
              -- Big insert will set IdleStyling to 0.
              -- Small insert will set IdleStyling to 3.
              -- Big is larger than 100 lines at 80 characters.
          
              if modType & SC_MOD_BEFOREINSERT then
                  if length > 8000 then
                      editor.IdleStyling = SC_IDLESTYLING_NONE
                  else
                      editor.IdleStyling = SC_IDLESTYLING_ALL
                  end
              end
          end
          
          
          local function FileIdleStyling()
              -- Big file will set IdleStyling to 0.
              -- Small file will set IdleStyling to 3.
              -- Big is larger than 1000 lines at 80 characters.
          
              if editor.Length > 80000 then
                  editor.IdleStyling = SC_IDLESTYLING_NONE
              else
                  editor.IdleStyling = SC_IDLESTYLING_ALL
              end
          end
          
          
          local function EventReady()
              -- User option.
              local useIdleStylingHandlers = true
          
              -- Set IdleStyling setting.
              if useIdleStylingHandlers ~= nil then
                  editor.IdleStyling = SC_IDLESTYLING_NONE
              end
          
              -- Register IdleStyling event handlers.
              if useIdleStylingHandlers then
                  npp.AddEventHandler('OnOpen', FileIdleStyling)
                  npp.AddEventHandler('OnSwitchFile', FileIdleStyling)
                  npp.AddEventHandler('OnModification', ModIdleStyling)
              end
          end
          
          
          npp.AddEventHandler('OnReady', EventReady)
          

          It mostly works OK though sometimes it does the 30 second styling so has it’s faults.

          The difference of identifier of AAA to 'AAA' made little difference with the lexer speed of processing as the later is simple string and yet took about the same amount of time to finish. Double quoted strings and here-doc string are interpreted with special characters so single quoted strings should be faster to process, seems not that much difference in time with my testing.

          PeterJonesP Min LiuM 2 Replies Last reply Reply Quote 1
          • PeterJonesP
            PeterJones @mpheath
            last edited by PeterJones

            @mpheath,

            If you want the old “just in time” aka JIT with only what is visual processing behavior, then install LuaScript/PythonScript/… plugin and change the idle styling setting.

            … That originally prompted me to think, “then we should ask Don to setIdleStyling(0) (NONE) before a paste and back to 3 (ALL) after the paste”. But then it hit me that keyboard-shortcut or menu paste are just calling the SCI_PASTE directly, AFAIR. So is that something that N++ can inject? Or would Scintilla itself have to be edited to redefine SCI_PASTE to temporarily disable SetIdleStyling during paste? (if the latter, do you know how to change SetIdleStyling in SciTE, so the behavioral difference can be made obvious to the Scintilla team?)


            I also confirmed that it was the commit to address “Enhance performance of syntax highlighting for large files. (Fix #15952)” in v8.7.6 that changed the setIdleStyling to ALL=3, so our concurrent investigations found the same cause. :-)

            mpheathM 1 Reply Last reply Reply Quote 1
            • mpheathM
              mpheath @PeterJones
              last edited by mpheath

              @PeterJones If LuaScript/PythonScript can do it with SC_MOD_BEFOREINSERT message then so can Notepad++. It is hard to know what the user may do to aggravate the current idle styling setting. If Scintilla knew best then there would not be multiple settings, rather a leave it with me and I will handle it, OK, no worries.

              SCI_PASTE should send a SC_MOD_BEFOREINSERT message which is why the Lua code posted uses it. It is before text is inserted so it knows that the paste is going to happen which if large, changes the idle setting.

              I like the 1 liner to set to 0. I think the opposite, small file = 3, larger files = 0. Larger files are always going to be proportional with processing problems when time is the measurement. Larger files need like a super computer to match the processing speed of small files.

              P.S. good tracing to the commit.

              PeterJonesP 1 Reply Last reply Reply Quote 1
              • PeterJonesP
                PeterJones @mpheath
                last edited by

                @mpheath said in Freezing when pasting large amount of text between quotes or heredoc (language PHP):

                SCI_PASTE should send a SC_MOD_BEFOREINSERT message which is why the Lua code posted uses it.

                Ah, sorry. I didn’t read the details of your detailed Lua script – I had thought it was just the hooks necessary to send the single message at startup (not using the LuaScript plugin, I don’t know how much overhead/boilerplate it would require for that), so didn’t read it for enough detail to see it was handling the notification.

                So yes, it looks like a fix like that would be technically feasible on N++'s side of things.

                Should it be proposed as a “Performance”-tab option to Don? ie, give users the choice of which of the four values they want, and have a fifth “3 normally but 0 during paste”? Or do you think it should just stay on the scripting end of things? Or do you think N++ should just do the fancy logic and not give users the choice? (And which of us should put in the Issue? I’ve got the good STR above, but you have a much better understanding of describing the fix than I do.)

                mpheathM 1 Reply Last reply Reply Quote 1
                • mpheathM
                  mpheath @PeterJones
                  last edited by

                  @PeterJones An option to change of idle styling like change of rendering could be useful for users. The paste handling is a bit of a scripting enhancement to try to tame the symptoms of the styling process set at 3 which is to style the whole doc. Setting idle styling to 0 processes the styling to only what is viewed and a one liner in a startup script might be enough. Perhaps if an issue is created then more users might join in with their experiences like this issue. Momentum might be needed to change the minds of those who believe in the what has previously been claimed as optimizations.

                  1 Reply Last reply Reply Quote 0
                  • Min LiuM
                    Min Liu @mpheath
                    last edited by

                    @mpheath @PeterJones
                    Thank you both for identifying the fault, although your discussion is a bit above my head :)

                    Just to check my understanding, Notepad++ is using a 3rd party plugin to do the formatting? and the suggestion is i install an alternative styling plugin for notepad++ which will override this new styling plugin which will allow me to revert to the former behaviour?

                    mpheathM 2 Replies Last reply Reply Quote 0
                    • mpheathM
                      mpheath @Min Liu
                      last edited by

                      @Min-Liu said in Freezing when pasting large amount of text between quotes or heredoc (language PHP):

                      Just to check my understanding, Notepad++ is using a 3rd party plugin to do the formatting?

                      Notepad++ sets the idle styling within it’s own source code. @PeterJones posted links to the change log, commits and issues. The setting was previously unset so was the default 0 which is no idle styling so only the visible document lines were styled. Then an explicit setting was added to set as 3 which is full document styling.

                      and the suggestion is i install an alternative styling plugin for notepad++ which will override this new styling plugin which will allow me to revert to the former behaviour?

                      A plugin can override the setting programmatically. Idle styling does not do styling, it is a setting that notifies if and how styling should occur. The suggestion with using a plugin can give you behaviour that you want now.


                      If your not into programming, then the easiest option currently is to install the LuaScript plugin from the menu Plugins -> Plugins Admin which is just 2 DLL files approximately 1 MB in size. Once Notepad++ is restarted then from the menu Plugins -> LuaScript -> Edit Startup Script which will open startup.lua in the editor. Add the line editor.IdleStyling = SC_IDLESTYLING_NONE. The SC_IDLESTYLING_NONE is a constant that represents the integer 0. Save and close the file startup.lua.

                      Notepad++ needs restart before the code in startup.lua will be run. After restart, the CPU of the computer will not need to work hard on styling when opening documents, switching documents, inserting text into documents that includes pasting … especially noticeable with large documents.

                      As your example shows, a small document can become a large document with just a single paste. 50,000 lines is a lot of styling to do so the document can get large in size.

                      I do not decide nor do the other users here decide what code is added or removed from the Notepad++ project. Some changes tagged as optimizations in the 8.7 series are in my opinion not optimizations. To have the idle styling setting reverted or added as a user option may need an issue posted at Github to get users involved to show that what is regarded as an optimization is undesirable. Until then, I regard LuaScript or similar plugins to change the idle styling setting to 0 as a users solution to this problem at present.

                      1 Reply Last reply Reply Quote 1
                      • mpheathM
                        mpheath @Min Liu
                        last edited by mpheath

                        @Min-Liu I would like some time to review the php lexer code as the powershell and python lexer shows better performance with the same text pasted under similar test conditions. Perhaps there is some bad code logic preventing good progression of the styling in the php lexer. This needs some proving in some way to recognize the lexer as bugged and will test in SciTE with similar settings to reproduce the bug.

                        LuaScript as suggested can help you for now though if the php lexer needs a fix then it should get priority with posting an issue and where it should be posted. This may take some time as the lexer code is complex.

                        @PeterJones I just tested in SciTE SC1 version 5.5.8 Scintilla:5.5.8 Lexilla:5.4.6 with idle.styling=3 in SciTEGlobal.properties. It pastes the 50,000 lines without freezing into a .php file. Can you possibly confirm this test as this implies the php lexer is OK in SciTE, yet is not OK in Notepad++. If confirmed, then the lexer seems OK and goes back to being a Notepad++ issue. The idle styling was not the only setting in Notepad++ that was changed. The versions of Scintilla/Lexilla match with Notepad++ 8.9.

                        https://scintilla.org/SciTEDoc.html#property-idle.styling

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors