Modify

Opened 4 years ago

Closed 2 years ago

#3794 closed Feature Request (Fixed)

StringRegExp - string passed by value instead by reference?

Reported by: AspirinJunkie Owned by: Jon
Milestone: 3.3.15.6 Component: AutoIt
Version: Severity: None
Keywords: StringRegExp Cc:

Description

Script:

; create a very large string (should be about 400 MB because UTF-16 is used)
Global $sString = ""
For $i = 1 To 20 * 1024 * 1024
    $sString &= "xxxxxxxxxx"
Next

; precompile pattern
StringRegExp("", "^.")

; determine time required for a small input string:
$iT = TimerInit()
StringRegExp("Test", "^.")
ConsoleWrite(StringFormat("RegEx with small input string: % 8.3f ms\n", TimerDiff($iT)))

; determine time required for a large input string:
$iT = TimerInit()
StringRegExp($sString, "^.")
ConsoleWrite(StringFormat("RegEx with large input string: % 6.1f   ms\n", TimerDiff($iT)))

Output:

RegEx with small input string:    0.012 ms
RegEx with large input string:  328.1   ms

The execution time depends directly on the size of the input string although only the first character of the string is processed.
If instead of StringRegExp a StringLeft or a StringMid is used then the execution times are independent of this.

This leads to the assumption that in the implementation of StringRegExp() at some point the input string is passed as "by value".
This would require the creation of a local copy of the string and would explain the loss of time.

If it is really a "by value" problem, i suggest to switch completely to "by reference" internally if possible. This would mean a massive performance gain for StringRegExp especially with large strings.

Attachments (0)

Change History (5)

comment:1 Changed 4 years ago by TicketCleanup

  • Version 3.3.15.3 deleted

Automatic ticket cleanup.

comment:2 follow-up: Changed 3 years ago by Jpm

  • Owner set to Jpm
  • Status changed from new to assigned

Fix sent to Jon.
Many thanks

comment:3 in reply to: ↑ 2 Changed 3 years ago by anonymous

Replying to Jpm:
Oh really cool. That would solve a lot of problems for me.
For completeness and out of interest: Was it really a "by value" problem?

comment:4 Changed 3 years ago by anonymous

ByValue create new local value (internally for function) for the same data passed to the function, so there must be allocated and copied memory related to the data set.
ByReference mean that function do not create new data set for the data passed to the function, but only use reference (like a link) to the data set in memory.

btw.
Next time please ask on the forum.

EDIT:
This was mine comment
mLipok

Last edited 3 years ago by mLipok (previous) (diff)

comment:5 Changed 2 years ago by Jon

  • Milestone set to 3.3.15.6
  • Owner changed from Jpm to Jon
  • Resolution set to Fixed
  • Status changed from assigned to closed

Fixed by revision [12648] in version: 3.3.15.6

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jon.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.