Re: Speeding up moto_createMotonameForFn
David Hakim <dhakim-Gkm/TONP9n1Wk0Htik3J/[email protected]> Sun, 11 May 2003 10:11:35 -0400
| Newsgroups | gmane.comp.lang.moto.devel |
|---|---|
| Message-ID | <[email protected]> |
On Sunday, May 11, 2003, at 05:57 AM, Stefano Corsi wrote:
>> It looks like moto_createMotonameForFn is really only taking 5% of the
>> time ... but this is misleading because almost all the time it is
>> called, the allocated fname is immediately freed. Plus, inside of
>> moto_createMotonameForFn a Stringbuffer is created, and appended to, a
>> toString operation is called (also expensive since it duplicates the
>> string), and the stringbuffer is freed. So we write a replacement
>> function which writes the fname to a static buffer.
>>
>> char*
>> moto_createMotonameForFnInBuffer(char* classn, char* fn, char*
>> buffer){
>> buffer[0]='\0';
>> if(classn != NULL) {
>> strcpy(buffer,classn);
>> strcat(buffer,"::");
>> }
>> strcat(buffer,fn);
>> return buffer;
>> }
>
>> This should be a noticeable speed improvement in interpreted code. Let
>> me know what your tests show!
>>
>> -Dave
>
> It is. I gained 7 seconds in this loop:
>
> void test0(int seed) {
> int a;
> for (a = 0; a < 100; a += 1) {
> int i;
> for (i = 0; i < seed; i += 1) {
> }
> }
> }
>
> print "test0\n";
> test0(10000);
>
> I have created the static buffer in env.c instead of passing it every
> time to
> createMotonameForFnInBuffer... something like
>
> char fnbuffer[200];
>
> and then every call to createMotonameForFnInBuffer uses the same
> buffer. Could
> this create problems if/when going multithreaded? Where is instead a
> good
> place for creating it? env->fnbuffer?
>
Yes, all interpreter globals should be put in env for the time being.
This way we only have one real process global , env itself, to deal
with when we make the interpreter multithreaded.
I suggest tho that we leave the fnbuffer to be passed in. I worry that
the semantics of createMotonameForFnInBuffer will quickly be forgotten
in the future and we will wind up with bugs like :
createMotonameForFnInBuffer
...
motoi(xxx)
...
print fname
where fname may get modified by the motoi call prior to use.
Also, there is no real performance gain from making the fnbuffer
global. Stack allocation doesn't cost anything at runtime.
-Dave
>
> Stefano
>