Any general tricks for speeding up macros?

Any general tricks for speeding up macros?

4
NewbieNewbie
4

    Nov 12, 2019#1

    Hello.
    I was recently forced to switch from notepad++ to UltraEdit, and the macros I use that run extremely fast under npp completely lock up under ue if doing more than a hundred or two executions.
    These are fairly simple macros too - for example converting a fixed length comma-delimited record into an insert statement.  Simple stuff.
    I turned off syntax highlighting, auto-complete and auto-bracing, which seems to help, but it's still pretty much unusable for what I need to do. I know it blanks out the screen after doing a dozen or so records, and I assumed that that was purposeful to help the macro run faster.
    So basically, I'm asking if there are any tricks I can do to speed up macros in general.  For instance, I wonder if one cause of slow-running macros is the undo tracking. Can that be turned off while a macro runs?  Any other ideas?
    Thanks!
    Paul

    6,675585
    Grand MasterGrand Master
    6,675585

      Nov 13, 2019#2

      The general trick to reduce the time an UltraEdit macro or script takes to complete a task is writing the macro or script to produce as less window updates as possible. This can be achieved usually using regular expression replace all commands to reformat a file with as less window updates as possible.

      For small files up to about 20 MB it is even possible to use a script which loads entire file content into memory of JavaScript core on execution of the script, reformat in memory the file content and output the reformatted text back to file with overwriting existing content. This results in just two window updates and in recording just one undo step and is the most efficient method to reformat a file for that reason.

      The time a macro or script needs to finish which results in lots of Windows updates can be reduced by using Classic theme of UltraEdit and if possible configure Windows to use also Classic theme (Windows 7). All those graphic effects like shading and color fading take a quite long time to be calculated and finally drawn on screen. In my experience with a macro processing a Windows registry file with more than 100 MB using mainly regular expression replace all commands the difference between Classic theme and the other non Classic themes is about factor 3, i.e. the macro takes three times longer to finish with themes like Slate or Modern Light in comparison to Classic theme. Well, I use a customized Windows 7 Classic desktop theme with having additionally disabled color fading in title bar of windows and use also a customized UltraEdit Classic theme because I like the puristic look and don't need a stylish look. That makes window updates most efficient, not only in UltraEdit, but in all Windows applications not ignoring completely the Windows desktop theme settings. Windows 10 is not used by me at the moment.

      The undo recording cannot be disabled with a macro or scripting command. No modifications are recorded for undo feature on using Replace in Files. It is possible to run Replace in Files on just active file. So it would be possible that a macro or script using just Replace All commands executed from top is modified to run just Replace in Files commands on this file for fastest reformatting of the file with just output window updates and without undo records.
      Best regards from an UC/UE/UES for Windows user from Austria

      4
      NewbieNewbie
      4

        Nov 14, 2019#3

        Hello Mofi,
        Your suggestions are excellent, I appreciate the advice very much. I will begin trying them at once.
        Regards,
        Paul

          Nov 14, 2019#4

          Hello,
          I have made great progress in improving the macro performance:
          Switched to UE classic theme.
          Switched desktop to Win7 basic.
          Turned off syntax highlighting.
          Then, accomplished 90% of the work by using simple find/replace-alls.
          So all that was left for my macro to do was to right-arrow to a couple specific columns to insert SQL function calls. This part still runs pretty slowly, but much faster than before.
          If I could figure out how to go to the specific columns rather than run having 100 'right-arrows' in my macro, that would make it run even faster, I'm sure. Any suggestion on how to do that? I could not see an obvious way in the list of commands.
          Thanks!
          Paul

          6,675585
          Grand MasterGrand Master
          6,675585

            Nov 15, 2019#5

            That's fine.

            The macro command to set caret to a specific column in current line is GotoLine 0 x whereby line number 0 is interpreted as current line and x is the column number with first column in a line having number 1.

            It would be also possible to use a Perl regular expression Find like Find MatchCase RegExp "^.{50}\K" to search for exactly 50 characters after start of a line and keep back found string which means nothing is selected and therefore just caret is blinking in line after the first 50 characters. Please note that the Perl regular expression find interprets a horizontal tab character as one character even if the tab takes multiple columns in displayed text depending on tab stop and indent value configured for active file.

            BTW: The parameter MatchCase is used although there is no difference between a case-sensitive and a case-insensitive regular expression find with this search string because of case-sensitive finds/replaces are always faster than case-insensitive finds/replaces. That is one more general trick to reduce macro execution time. Finds/replaces should be run case-sensitive wherever possible.
            Best regards from an UC/UE/UES for Windows user from Austria

            4
            NewbieNewbie
            4

              Nov 15, 2019#6

              The 'gotoLine' was the most effective of all improvements so far.  Instead of issuing a 'home', then a 'down arrow', then 100 'right arrows' to get to where I wanted to be, now all I need is the down arrow then the gotoLine 0 100.  
              So overall, I would say my macro has improved by a factor of 20.  And I've gone from disappointed in UE (compared to NPP), to extremely pleased.
              Regards,
              Paul