Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2009-02-26
02:59 • Closed ticket [2613766fff]: performance loss from NRE-enable of source plu... artifact: bfef3d12f9 user: dgp
2009-02-25
04:44 • Ticket [2613766fff]: 4 changes artifact: 391113faba user: dgp
2009-02-24
05:40 • Ticket [2613766fff]: 5 changes artifact: 0c5affc59c user: dgp
2009-02-23
20:10 • Ticket [2613766fff]: 5 changes artifact: a79b057f49 user: dgp
12:31 • Ticket [2613766fff]: 4 changes artifact: 542eeed405 user: dgp
12:00 • Ticket [2613766fff]: 4 changes artifact: a6ac98b33a user: dgp
10:10 • Ticket [2613766fff]: 4 changes artifact: d4682fe0e8 user: hobbs
09:58 • Ticket [2613766fff]: 4 changes artifact: 54fad039bb user: dgp
2009-02-22
21:43 • Ticket [2613766fff]: 4 changes artifact: a991395aa5 user: dkf
11:59 • Ticket [2613766fff]: 6 changes artifact: 791d05e750 user: dgp
2009-02-19
09:50 • Ticket [2613766fff]: 4 changes artifact: 44e537b4ca user: dgp
2009-02-18
19:46 • New ticket [2613766fff]. artifact: c9aa37f446 user: dgp

performance loss from NRE-enable of [source]

Closed / Fixed2613766fffffffffffffffffffffffffffffffffCreated 18 years agoUpdated 18 years ago
Descriptionplain2009-02-18 19:46:23
Something since 8.6b1 has dropped the
performance of the tclbench test noted
in the summary by about a factor of 2.
dgpplain2009-02-19 09:50:42
A bit less cryptically this script
demo's the slowdown:

proc demo {s e} {
    regexp $e $s
}
demo a[string repeat b 200] a.*b.*c
dgpplain2009-02-22 11:59:17
some bisection blames the 
"NRE-enable [source]" commit
from 2009-01-05 for the loss.
dkfplain2009-02-22 21:43:43
That would (probably) indicate a shimmering problem. I didn't do anything with the RE code in that commit.
dgpplain2009-02-23 09:58:41
The difference is due to the
objtype of $::str when that test
runs.  In older Tcl, it's the
"string" Tcl_ObjType; in the current
HEAD it's an untyped value.  Then
the performance difference is
the difference between doing
a glob match on a unicode array
or on a utf encoded string.
hobbsplain2009-02-23 10:10:47
I haven't checked the specifics, but note the a.*b.*c RE case was made slower by my changes to REToGlob at some point.  They sped up the more common a.*b, but more than one .* shows the RE is still faster.  I never got around to the code that counts the .*'s and falls back to RE with more than 1 present.
dgpplain2009-02-23 12:00:31
The simplest way to restore the
lost performance is to add the
flag TCL_EVAL_DIRECT to the
TclNREvalObjEx() call at line 1869
of file tclIOUtil.c

That change also solves the failing
tests in info.test (2487771).

Unfortunately, it also causes test
source-8.1 to fail.  This raises
some questions.

Is the TCL_EVAL_DIRECT flag supposed
to be a valid thing to pass to
TclNREvalObjEx() ?

If so, why is it causing source-8.1
to fail?

If not, why is there still code in
that routine to handle that flag?
Also, what about all the callers?
Do they all take care to be sure
that flag value doesn't flow through?
dgpplain2009-02-23 12:31:11
Assuming that change isn't feasible,
the performance loss comes down to
a difference in the objtype of
words produced by TclSubstTokens
and by TclCompileTokens.
dgpplain2009-02-23 20:10:57
the other knob to twist on this
one is to look at the handful of
places that operate on the unicode
array rep of a value iff the value
already has the "string" objType.
Might make sense to broaden that net
to capture untyped values as well.
We still avoid shimmering away intreps
of other types that might have value,
and this test at least suggests that
the performance gains of working
with unicode are so significant that
they win even if you have to create
the unicode rep from scratch as part
of the operation.
dgpplain2009-02-24 05:40:40
Other tests with more modest performance
loss due to the same commit are:

460 SPLIT iter, rand 100 c
471 SPLIT, rand 100 c
483 STR append (10KB + 1KB)

These in addition to the original
report about benchmark:

420 RE var backtrack case

The slowdowns of both 420 and 483
are corrected by adding the
TCL_EVAL_DIRECT flag.
dgpplain2009-02-25 04:44:08
For benchmark 483, the loss is completely
due to a realloc() call changing from
one that can return the same pointer value
to an enlarged space to one that must
return a different pointer value.  Apparently
a symptom of memory fragmentation.
dgpplain2009-02-26 02:59:36
allow_comments - 1


fixed by creating/using unicode
rep on untyped values.
Log in (anonymous is fine) to add a comment.