Android ways to speed up few readings from files


In my application I need to load some files, when the app starts. I have 6 different files, which content int arrays and I need to read them as fast as possible. 3 of them content 80K ints, other 200K ints

Here is method that I'm using to read int array from file

public static int[] loadByMappedBuffer(Context context, String filename) throws IOException{ FileInputStream fis = context.openFileInput(filename); FileChannel ch = fis.getChannel(); MappedByteBuffer mbuff = ch.map(MapMode.READ_ONLY, 0, ch.size()); IntBuffer ibuff = mbuff.asIntBuffer(); int[] array = new int[ibuff.limit()]; ibuff.get(array); fis.close(); ch.close(); return array; }

As you see I'm using nio to read arrays. Here is result of testing, when I'm reding single file, which content 80K ints

<ul><li>Sony Ericsson Experia with best time of 104 ms and worst of 270 ms</li> <li>Nexus 7 with best time of 20.14 ms and wors of 48.36</li> <li>Samsung Galaxy Note 10.1 (2014 Edition) with best time of 1.16 ms and worst of 5.82 </li> </ul>

So for single reading it works fine, but when I'm reading all 6 files (which I mentioned above) the results will be following

<ul><li>Sony Ericsson Experia with best time of 1396 ms and worst of 3324 ms</li> <li>Samsung Galaxy Note 10.1 (2014 Edition) with best time of 58 ms and worst of 115 ms</li> </ul>

First of all I don't understand why cache don't kicks in after first reading, like on PC.

At this time I have 2 ideas

<ol><li>find a better way to read files (but nio is the fastest way to read primitives from files, as far as I know)</li> <li>use MT programming and put file readings to threads, which will speed up this, but only for devices, which has CPU with more than one core, I'm right?</li> </ol>

I had heared that Async Task is something like threads, can it bee helpful for my purpose?

Any ideas will be appreciated. Thanks in advance


threads are not only for parallel computing, they're used for better UX, so the user can still interact with the app while it's doing stuff in the background. AsyncTask is very nice, although if you're short on time a simple thread written correctly should be faster.

now, if the app loads files, you can do it in parts (like 10% of every file), show those parts, and continue to load the rest in the background.

i think trying to read faster is the wrong direction here, because that's very hardware dependent. some devices would be slow no matter how hard you try.. think about a UX that's OK for all cases.

hope that helps


  • Stream types in C++, how to read from IstringStream?
  • Android load local xml file
  • Set color for SWT Combo
  • java.lang.NoClassDefFoundError: java.awt.geom.Rectangle2D$Double while trying to parse a pdf page to
  • Would you consider this a proper test case?
  • Struct Alignment with PyOpenCL
  • How to remove an object from ManyToMany relationship in Django Rest Framework
  • Writing the stored procedure without cursor [duplicate]
  • Python openpyxl read until empty cell
  • the directory is already locked hadoop
  • Android non-blocking file i/o?
  • Spring cloud config server not loading the properties files
  • itext font UnsupportedCharsetException
  • nhibernate queries SubQueryExpression
  • Find group of records that match multiple values
  • Why use database factory in asp.net mvc?
  • preg_replace Double Spaces to tab (\\t) at the beginning of a line
  • Change multiple background-images with jQuery
  • ImageMagick, replace semi-transparent white with opaque white
  • Sails.js/waterline: Executing waterline queries in toJSON function of a model?
  • Android screen density dpi vs ppi
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • Running a C# exe file
  • sending/ receiving email in Java
  • Change an a tag attribute in JavaScript based on screen width
  • Redux, normalised entities and lodash merge
  • Do create extension work in single-user mode in postgres?
  • php design question - will a Helper help here?
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • AngularJs get employee from factory
  • Load html files in TinyMce
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • coudnt use logback because of log4j
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Authorize attributes not working in MVC 4
  • Django query for large number of relationships
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Reading document lines to the user (python)
  • How can I use `wmic` in a Windows PE script?
  • How to push additional view controllers onto NavigationController but keep the TabBar?