Saturday, 15 March 2014

java - Why is this Android code so slow? -


I have a contour plot rendering routine which is ignition fast; it is basically the OnPaint event Presents some form in, and updates very quickly ... Basically the faster you can move the mouse I was very pleased with it. It is based on this paper:

However, I put it on Android / Java and targeted a very fast tablet (Nexus 9) and this is surprisingly slow , Where should I use the wrong approach that I think. Basically I:

1) Create a visual programmatically, 2) Apply the ONDA method to call your C Cantoplate class draw method, which repeats through 2DD data arrays. , The 1-D "cans" array, and the "DrawPolygonRegion" function makes a few thousand calls that I wrote below.

It takes an amazingly long time, compared to NAT at approximately 100x slow, at the point where I am thinking that I am doing something wrong specific questions:

a) What speed is speed-tweakable down? Is using a path a faster way to attract polygon? (There is a droplie function in the .NET, something new to the Android port was doing) b) Do I need to do something to "batch" my rendering commands? Canvas (spec) such. SuspendUpdates, Canvas.ResumeUpdates? C) Do I need to activate double buffering or something else? My quick research says that it is done automatically in Android, but it is not sure. (I had to activate it at NAT, but I'm sure if I do not want here)

Thank you very much for any insights / support.

  Zero DrawPolygonRegion (canvas c, int color, double ... p) {int length = p.length; If (length> = 6) {paint.setColor (color); Paint.setStyle (Style.FILL); Path path = new path (); Path.moveTo (Float) P [0], (Float) P [1]); // the first point used for path.lineTo (float) P [2], (float) p [3]); Path.lineTo (Float) P [4], (Float) P [5]); Int idx = 6; (Int n = 6; n & lt; length; n + = 2) {path.lineTo (float) p [n], (float) p [n + 1]) for; } CDRPath (path, paint); }}  

Call it a few thousand times Oh yeah, you have some problems.

1) It allocates a new path. Quickly add allocation to Android, try to avoid them, like reusing objects, especially on on-douf Functions.

2) You should not really build the entire path at all times - they are better saved and reused in append mode.

3) Downstream to float from double to free is not free. Avoid it

4) Are you doing it straight on the screen canvas? do not do. Come to a bitmap canvas in your own thread, and throw the results in the canvas of the screen.

I suspect that this code is moving on the net with PCs with better processor and RAM. I think your butt is being saved by hardware acceleration.


No comments:

Post a Comment