how expensive findViewById ??

by Alexey » Tue, 14 Apr 2009 00:04:39 GMT


Sponsored Links
 Hi all, trying to find some performance numbers for findViewById -
need to convince  to change bunch of the findViewById for the same
widget to member variable with just one findViewById on create . Or
may be i'm wrong and it's fine ?
--~--~---------~--~----~------------~-------~--~----~



how expensive findViewById ??

by Michael Bollmann » Tue, 14 Apr 2009 00:20:39 GMT


 It depends on how often you call it and what your app is doing anyway.
Now matter how good it's implementation is access to a member variable
is always much faster than a function call.
On the other hand you might not notice any improvement in case your
app does some stuff that takes
1000 times longer than a call to findViewById.

Take a look at this: 
 http://developer.android.com/guide/practices/design/performance.html #samples



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


how expensive findViewById ??

by Alexey » Tue, 14 Apr 2009 00:43:00 GMT


 yeah, that reference doesn't have number i'm looking for.

On Apr 13, 11:20am, Michael Bollmann



--~--~---------~--~----~------------~-------~--~----~



how expensive findViewById ??

by Michael Bollmann » Tue, 14 Apr 2009 01:09:22 GMT


 I guess findViewById uses some kind of map implementation with O(log
n)
So my guess is that it's about 100-200 compared to 0 when you use
member access.





--~--~---------~--~----~------------~-------~--~----~



how expensive findViewById ??

by Dianne Hackborn » Tue, 14 Apr 2009 02:53:43 GMT


 Actually it's not nearly so smart -- it is just a traversal through the view
hierarchy until it finds a matching id.

As with all things, you should avoid doing this repeatedly if you don't need
to (keep the thing you find in a variable so you don't have to look it up
again).  For more subtle performance questions, the profiler is really what
you need to use.

On Mon, Apr 13, 2009 at 10:09 AM, Michael Bollmann <








-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~



how expensive findViewById ??

by Alexey » Tue, 14 Apr 2009 03:49:23 GMT


 Thanks. that answers my question.







--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Can a Nexus One be used for development?

I want to buy a Nexus One for my business but I want to develop apps too, do
I need another phone (thinking about a Hero) to develop or can I use the
Nexus one as development phone and everyday phone as well? If I need another
phone to do development, can I use a Hero?

Thanks

Fred

-- 

2. Google Goggles translation to be an IME?

I was watching this Google Goggles prototype showing how taking a
picture of some text can be conveniently translated into whatever
language you specify:

http://www.youtube.com/watch?v=ae01yz5z99E

Would be great if this could be an IME and that you could specify
whether to translate the OCR output or not.

Personally, I would love to be able to point my camera at some chinese
text and get that OCR'd via an IME.

Thoughts?

-- 

3. How to make a custom view/activity with many screens like home screen in 2.x

4. Mirink jogja yuk

5. Android app only taking up part of screen

6. Perbedaan f/w or rom ori/bawaan

7. New Android SDK Tools, Eclipse plug-in and NDK