17

In java there is an optimal buffer size of 32 Kb which is based solely on the cpu architecture being used. On Android phones does the Dalvik VM dynamically know the proper cache of the cpu to get the largest buffer size independent of the many different phones out there? If so how would I figure that out at runtime?

Say I want to optimize a audio recording activity by making the buffer the largest it can be and also the fastest. I know you can get the minimal size for it but what about the optimal size?

3
  • You really mean Dalvik VM when you say JVM right? Commented Apr 13, 2012 at 15:37
  • @slayton yes, the Dalvik VM specifically Commented Apr 13, 2012 at 16:16
  • I'd also like to point out that this has a little to do with android and audio latency, its not the only reason for poor latency but it is a contributing factor, see developers.google.com/events/io/sessions/325993827 for a better explanation Commented Jun 4, 2013 at 1:14

1 Answer 1

54

Maybe it depends on what device you have or mind.

However, experimentally, 8K < buffer size < 32K does work well and there are significant performance improvements under 8K. Somewhat interesting is that some data with buffer > 64K showed poorer performance than data with under 64K buffer

(I've tested on several android devices and tried to read 20MB binary file with various buffer size.)

Here's exp result and you'd better to paste them to spreadsheet if you wanna convert data in pretty form. header means buffer size and units are millisecond

graph: http://fb.com/photo.php?fbid=468345876512381

 128 256 512 1K 2K 4K 8K 16K 32K 64K 128K 256K 512K 1M 2M 4M 8M 16M Galaxy S 4047 3060 269 155 100 65 64 52 51 45 47 50 49 43 44 46 45 58 Optimus LTE 1178 617 322 172 101 65 47 42 41 35 36 39 44 61 56 51 72 60 HTC EVO 3971 1884 941 480 251 141 95 69 56 50 48 55 50 49 48 48 48 47 Galaxy S2 750 383 210 123 74 50 41 37 35 34 34 37 39 44 46 44 45 44 Galaxy Nexus 2272 1216 659 341 187 108 70 52 41 38 38 45 44 54 56 66 68 58 Galaxy Note 1549 799 404 220 127 75 58 54 52 56 52 45 44 62 43 39 44 46 

InputStream in = openFileInput(FILE_NAME); startTime = System.currentTimeMillis(); while (in.read(buffer) > 0) { readCount++; } elapsedTime = System.currentTimeMillis() - startTime; 

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

huh it looks like 32K is where the money is at based on your graphs
@L7ColWinters yep, I agree with you :)
I can't view the graph.
@FelixD. I attached graph

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.