Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid performance issues in populating ArrayList
    text
    copied!<p>I've created a method to populate an array based on a Http response I get from a server. I receive the response in a simple format and read it with a Scanner. The response has only around 8000 entries (floats and integers), and it's taking forever to populate the ArrayList, around 1 or 2 minutes. Here is the code</p> <pre><code>public void update(String str) { ProgressDialog pDialog = new ProgressDialog(context); pDialog.setMessage("Atualizando pesos, aguarde"); pDialog.show(); BufferedReader r = new BufferedReader(new StringReader(str)); Scanner s = null; try{ s = new Scanner(r); ArrayList&lt;ArrayList&lt;ArrayList&lt;Double&gt; &gt; &gt; weights = new ArrayList&lt;ArrayList&lt;ArrayList&lt;Double&gt; &gt; &gt;(); while(s.hasNextInt()){ ArrayList&lt;ArrayList&lt;Double&gt; &gt; wl = new ArrayList&lt;ArrayList&lt;Double&gt; &gt;(); int layerId = s.nextInt(), neuronsAmt = s.nextInt(), inputSize = s.nextInt(); Log.d("UpdateTask", "Layer " + layerId + ", neuronios: " + neuronsAmt + ", inputSize: " + inputSize); for(int i = 0; i &lt; neuronsAmt; i++){ ArrayList&lt;Double&gt; wi = new ArrayList&lt;Double&gt;(); for(int j = 0; j &lt; inputSize; j++){ wi.add(s.nextDouble()); } wl.add(wi); } weights.add(wl); this.weights = weights; if(s.hasNext() &amp;&amp; !s.hasNextInt()) Log.d("UpdateTask", "Depois de tudo tem " + s.next()); } }finally{ if( s != null) s.close(); pDialog.dismiss(); } } </code></pre> <p>I'm calling it from an AsyncTask after the HTTP response is received.</p> <p>EDIT: I'll try to explain the HTTP structure here. The response actually gives the weights for a neural network. Basically it's an array of matrices (which should remain as matrices, for the evaluation of the neural network to work). The HTTP response is as follows: There are N matrices. Each one starts with an integer (the matrix ID), followed by the number of rows(R) and the number of columns(C) in the matrix. After that, there are R*C floats indicating the value stored in the matrix. Input is terminated when you can't find another layer id.</p> <p>PS: I wasn't able to make the dialog work either, but that's not a problem for me now.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload