Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2000-10-26
08:24 • Closed ticket [218556ffff]: Tcl8.1b1 regexp's are now 17 times slower than i... artifact: f5d25cbb3a user: welch
01:02 • New ticket [218556ffff]. artifact: 5de72b5c09 user: nobody

Tcl8.1b1 regexp's are now 17 times slower than in Tcl8.0.4

Closed / Fixed218556ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 01:02:08
OriginalBugID: 1063 Bug
Version: 8.1b1
SubmitDate: '1999-01-15'
LastModified: '1999-08-04'
Severity: SER
Status: Released
Submitter: pat
ChangedBy: stanton
OS: Windows NT
OSVersion: 4.0
Machine: X86
FixedDate: '1999-06-01'
FixedInVersion: 8.1.1
ClosedDate: '2000-10-25'


Name:
vince darley

Extensions:
none

CustomShell:
none

ReproducibleScript:
proc scancontext {cmd args} {
    switch $cmd {
"create" {
    uplevel 1 {
set __scan 0
while {[array exists scancontext$__scan]} {
    incr __scan
}
set scancontext[set __scan]() 1
return scancontext$__scan
    }
}
"delete" {
    upvar [lindex $args 0] scan
    unset scan
}
    }
}

proc scanmatch {scanid regexp script args} {
    if {[string match "-*" $scanid]} {
set flags $scanid
set scanid $regexp
set regexp [list $flags $script]
set script [lindex $args 0]
    } else {
set regexp [list -- $regexp]
    }
    upvar $scanid scan
    set scan($regexp) $script
    return $scanid
}

proc scanfile {scanid fid} {
    upvar $scanid scan
    upvar matchInfo m
    set m(linenum) 0
    set m(offset) 0
    while {[set count [gets $fid m(line)]] >= 0} {
incr m(linenum)
incr m(offset) $count
foreach reg [array names scan] {
    if {$reg == ""} {continue}
    if {[regexp [lindex $reg 0] [lindex $reg 1] $m(line)  "" m(submatch0) m(submatch1) m(submatch2)]} {
uplevel 1 $scan($reg)
    }
}
    }
}

proc test {} {
    global tk_library
    set cid_scan [scancontext create]
    scanmatch $cid_scan  "^\[ \t\]*(proc|while|if|blah)" {
incr count 1
    }
    scanmatch $cid_scan "^\[ \t\]*(foreach|namespace|global)" {
incr count 1
    }

    set count 0
    foreach f [glob -nocomplain [file join $tk_library *.tcl]] {
if {![catch {open $f} fid]} {
    scanfile $cid_scan $fid
    close $fid
}
    }

    scancontext delete $cid_scan

}

time test 10

ObservedBehavior:
Running this script under Tcl 8.0.4 takes 2.4 seconds per iteration.
Under Tcl 8.1a2 it was about 7.5 times slower
Under Tcl 8.1b1 it is SEVENTEEN (yes 17) times slower than Tcl 8.0.4, it takes more than 40 seconds per iteration.

The script basically makes repeated use of simple regexp's like 

"^\[ \t\]*(proc|while|if|blah)"

DesiredBehavior:
I expect regexps using the new engine to be faster, not slower than tcl8.
In particular, a slowdown of a factor of 17 is simply unacceptable.  I will never be able to use Tcl 8.1 in many of my applications if this is not fixed.



This is a known bug.  This, rather extensive example, points out that a global regexp object needs
to be cached and reused when compiling regular expressions.  This will prevent the shimmering.
03/23/1999 18:00 - surles -

A second level cache has been added that should fix this problem.
05/12/1999 18:38 - stanton -
welch Closed ticket [218556ffff]. [History diff]2000-10-26 08:24:14
Log in (anonymous is fine) to add a comment.