Tk Source Code

View Ticket
Login
Ticket UUID: 1076063
Title: Empty test performance issue from c.l.t
Type: Bug Version: obsolete: 8.4.6
Submitter: dkf Created on: 2004-11-30 15:12:45
Subsystem: 23. Option Parsing Assigned To: hobbs
Priority: 5 Medium Severity:
Status: Closed Last Modified: 2026-10-22 17:22:33
Resolution: Fixed Closed By: serhiy.storchaka
    Closed on: 2026-09-25 09:16:01
Description:
From: Khamis Abuelkomboz <[email protected]>
Newsgroups: comp.lang.tcl
Subject: performace issue in Tk
Date: Mon, 29 Nov 2004 22:15:50 +0100
Organization: T-Online
Message-ID: <[email protected]>

Hi

I have found a performance and memory usage issue in
the function ObjectIsEmpty implemented in 
tk8.4.6\generic\tkConfig.c:2229

To test if an object is empty it just convert every
object into a string. this is pretty ugly, if 
you have lists in the options list. it converts all
lists, integers and so on into strings. as 
example, with my fix I reduced memory usage from 200MB
to 110MB by large amount of data. It got even 
  some factors faster.

here is the origin

static int
ObjectIsEmpty(objPtr)
     Tcl_Obj *objPtr;/* Object to test.  May be NULL. */
{
     int length;

     if (objPtr == NULL) {
return 1;
     }
     if (objPtr->bytes != NULL) {
return (objPtr->length == 0);
     }
     Tcl_GetStringFromObj(objPtr, &length);
     return (length == 0);
}

and the modified version

static int
ObjectIsEmpty(objPtr)
     Tcl_Obj *objPtr;/* Object to test.  May be NULL. */
{
     int length;

     if (objPtr == NULL) {
return 1;
     }
     if (objPtr->bytes != NULL) {
return (objPtr->length == 0);
     }
++++++>>>>>>>
     if (objPtr->typePtr != NULL)
     {
if (stricmp(objPtr->typePtr->name, "list") == 0)
{
    List *listRepPtr = (List *)
objPtr->internalRep.twoPtrValue.ptr1;
    int numElems = listRepPtr->elemCount;
    return (numElems == 0);
}
if (stricmp(objPtr->typePtr->name, "string") != 0)
    return 0;
     }
++++++<<<<<<<<
     Tcl_GetStringFromObj(objPtr, &length);
     return (length == 0);
}

-- 
Try Code-Navigator on http://www.codenav.com
a source code navigating, analysis and developing tool.
It supports almost all languages on the scope.
User Comments: serhiy.storchaka added on 2026-09-25 09:16:01:

Fixed in 9.1 by [04148fbb6e]: with Tcl 9.1 Tk checks for an empty value with Tcl_IsEmpty(), which does not generate a string representation. 8.6 and 9.0 are unchanged. Closing.