Overview
| Artifact ID: | e3e88f0be665938008784d9ad8bd281a0be926b69afa3475867172c1bffe431d |
|---|---|
| Ticket: | da16d155744c55d5a769a81b57b0e80045e8391a
unacceptable long file read time by fix of [db4f2843cd] |
| User & Date: | oehhar on 2024-01-22 13:54:23 |
Changes
- icomment:
I made some tracing sessions with the two versions: Old: <verbatim> Tcl_AppendToObj(objPtr, NULL, dstLimit); </verbatim> and New: <verbatim> Tcl_SetObjLength(objPtr, numBytes + dstLimit); </verbatim> IMHO, the performance difference comes from the different allocation strategies of the 4096 bytes read by each read command. Each command grows the buffer by 4096 bytes (plus 2 bytes for eventual full utf code (on 8.6 with TCL_CHAR_MAX=3). The old method uses GrowStringBuffer() which doubles the buffer on each run. In consequence, only a much smaller amount of realloc-calls is used, but eventually a large chunk of memory is wasted. The new method uses ckrealloc() for each chunk of 4096 bytes. The test string size is 1000000000. So 1000000000 / 4096 = 244141 reallocs happen with increasing size. The great factor-two logic of GrowStringBuffer() is probably not used by Tcl_SetObjLength(), as this does not signal the potential of a future growth. The 2nd comparison of the two methods is, if a UNICODE string is prefered. The called routine is "Tcl_AppendLimitedToObj()". Here is the preference of Unicode as stated by Sergey: <verbatim> if (stringPtr->hasUnicode && stringPtr->numChars > 0) { AppendUtfToUnicodeRep(objPtr, bytes, toCopy); } else { AppendUtfToUtfRep(objPtr, bytes, toCopy); } </verbatim> In the tracing I did, there is never a chance to get a UNICODE string. In consequence, I would suggest the following: - unwind the patch - add a test, that unicode is never in the buffer at this position. As in both cases "SetStringFromAny(NULL, objPtr)" is called, an eventual unicode representation may be invalidated after this call. SOmething like: <verbatim> SetStringFromAny(NULL, objPtr); stringPtr = GET_STRING(objPtr); stringPtr->hasUnicode = 0; stringPtr->numChars = -1; </verbatim> Is this a plan ? Thank you and take care, Harald - login: "oehhar"
- mimetype: "text/x-fossil-wiki"
- username: "oehhar"