Marcus Crafter wrote:

>On Thu, Mar 07, 2002 at 09:55:53AM -0500, Berin Loritsch wrote:
>
>>How often are profilables registered with the profiler?  The
>>question arrizes out of a possibility to make the API a little
>>nicer.
>>
>>If this action happens very often, the API needs to stay the same
>>because arrays are more efficient.
>>
>>However, if the action only happens once in a great while (like
>>during initialization), we should take advantage of the Java
>>collections API to make things a bit smoother.
>>
>
>       I don't think it's the registration of profilables that would be done
>       all that often - it's probably more the traversal of
>       profilables/profile points to select which will be sampled, etc.
>
What part of the API are you referring to?  Profilables are only 
registered when they are
created.  This means that ThreadSafe components are only registered 
once.  Poolable, once
for each new instance.  But the SingleThreaded components are registered 
once for each
instance, which translates into once per lookup.

Do you mean the getProfilePoints() and getChildProfilables() methods in 
the Profilable interface?
I felt that arrays were a good choice here because the implementor has 
more choices in how they
create the array.
Also the code this way looks like this:
    public ProfilePoint[] getProfilePoints()
    {
        return new ProfilePoint[]
        {
            m_randomQuickProfilePoint,
            m_randomSlowProfilePoint,
            m_randomRandomProfilePoint,
            m_counterQuickProfilePoint,
            m_counterSlowProfilePoint,
            m_counterRandomProfilePoint,
            m_doActionProfilePoint
        };
    }

as opposed to:
    public Collection getProfilePoints()
    {
        ArrayList list = new ArrayList(7);
        list.add( m_randomQuickProfilePoint );
        list.add( m_randomSlowProfilePoint );
        list.add( m_randomRandomProfilePoint );
        list.add( m_counterQuickProfilePoint );
        list.add( m_counterSlowProfilePoint );
        list.add( m_counterRandomProfilePoint );
        list.add( m_doActionProfilePoint );
        return list;
    }

I like the first choice :-)

I make use of arrays in many other APIs to avoid synchronization issues. 
 The arrays are created
as needed and then stored outside of any synchronization.  This makes it 
easy for the 99.9% of
the calls in which the contents of the array have not changed.

Cheers,
Leif

Reply via email to