Community
    • Login

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

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 4 Posters 88 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
      last edited by

      Hi,
      I’ve been using Notepad++ for several years however one of the later updates v8.7 and above (currently running 8.9 64bit) is causing the app to hang when pasting large amounts of text in.

      This only occurs when:

      1. language is set to PHP
      2. text is pasted between quotes or a heredoc

      Does not occur if language is switched to something else, data pasted, then changed back.

      Does not occur if language is set to PHP and the entire file contents is pasted in.

      Example:
      Start with a blank file, set language to PHP.
      Paste in:
      <?php

      $a =<<< AAA

      AAA

      then paste in 15000 lines of
      AAAAAA 9999

      Plugins installed:
      Mime tools
      Npp converter
      NppExport

      Alan KilbornA 1 Reply Last reply Reply Quote 2
      • Alan KilbornA
        Alan Kilborn @Min Liu
        last edited by

        @Min-Liu

        You should post your Debug Info.

        Does it hang forever or does it just take what seems like a really long time?

        Min LiuM 1 Reply Last reply Reply Quote 0
        • 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 1 Reply 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.)

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