string repeat speedup by pre-allocating TclObj
Closed / Fixed219109ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 25 years ago
Descriptionplain2000-10-26 01:10:55
OriginalBugID: 6018 RFE
Version: 8.3.1
SubmitDate: '2000-07-18'
LastModified: '2000-09-26'
Severity: LOW
Status: Released
Submitter: techsupp
ChangedBy: hobbs
OS: All
FixedDate: '2000-09-26'
FixedInVersion: 8.4a2
ClosedDate: '2000-10-25'
Name:
Bob Techentin
Comments:
It would probably be even more efficient to copy the guts of
AppendUtfToUtfRep (in tclStringObj.c) but that might be
reaching down to too low a level for this command. I tried it
and got 75% speedup, but it core dumps in the corner cases in
the test suite.
DesiredBehavior:
The new [string repeat] command will iteratively call Tcl_AppendToObj()
to build up a repeating string. This causes several calls to reallocate more
memory for the result object. It is more efficient to call Tcl_SetObjLength()
once before the appends, so that it is not necessary to reallocate memory
while building up the string. This results in about a 20% speedup on my
system, and reduces the chances of the automatic allocator using too much
memory (it doubles the object length each time).
Patch:
*** tclCmdMZ.c.orig Mon Jul 17 14:51:48 2000
--- tclCmdMZ.c Mon Jul 17 15:26:56 2000
***************
*** 1823,1828 ****
--- 1823,1829 ----
string1 = Tcl_GetStringFromObj(objv[2], &length1);
if (length1 > 0) {
+ Tcl_SetObjLength(resultPtr, count*length1);
for (index = 0; index < count; index++) {
Tcl_AppendToObj(resultPtr, string1, length1);
}
PatchFiles:
tclCmdMZ.c
That simple fix unfortunately doesn't have the desired effect,
but I've changed around 8.4a2 to use ckalloc directly for the
same effect.
-- 09/26/2000 hobbs
welch Closed ticket [219109ffff].
[History diff]2000-10-26 08:34:57
dgp Open ticket [219109ffff].
[History diff]2001-04-05 08:01:24
dkf Closed ticket [219109ffff].
[History diff]2001-06-26 05:50:48
Log in (anonymous is fine) to add a comment.