performace issue in Tk

From: Khamis Abuelkomboz (khamis_at_wellcode.com)
Date: 11/29/04


Date: Mon, 29 Nov 2004 22:15:50 +0100

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.


Relevant Pages

  • Re: performace issue in Tk
    ... > I have found a performance and memory usage issue in the function ... > string. ... if you have lists in the options list. ... I've logged it in our bug database on ...
    (comp.lang.tcl)
  • Re: Fastcode Trim B&V 0.3.0
    ... most important performance metrics for me are speed and memory usage. ... such as in the case of Trim. ... The scenario in which the fact that trim does not return a unique string ...
    (borland.public.delphi.language.basm)
  • Re: Object#freeze as a basis for caching of method results?
    ... > on memory usage. ... If the String is short enough that approach is ... just marshalling... Demarshalling was the option I had thought of. ...
    (comp.lang.ruby)
  • Re: ListView FindItem
    ... Instr() seems to have a limit to the size of the string it can test. ... Do not want to double memory usage by putting the value in the collection ... ' use InstrRev to find the last delimiter, then use Left$ to get only ...
    (microsoft.public.vb.general.discussion)
  • Re: Stringbuilder and SelectCommand
    ... that the strings were large enough that their memory usage is significant. ... if the new string that you are going to construct is going ... The old "alloca" statement that allowed for allocating ... EQ, even when no players were in a particular spot, the server kept ...
    (microsoft.public.dotnet.languages.csharp)