Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Android - fastest way to fill a [Byte|Float|Int]Buffer  (Read 2744 times)
0 Members and 1 Guest are viewing this topic.
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Posted 2014-02-01 17:19:29 »

I've been porting some code from desktop to Android and suddenly found my loading times were up to a couple of minutes. Turns out this was due to filling a ByteBuffer with initial pixels for a new texture.

Looping over all the pixels and doing relative ByteBuffer.put(byte) calls was taking ~10. But creating a temporary array, looping over that and then doing a single bulk ByteBuffer.put(byte[]) takes about 500ms. Filling the array with Arrays.fill() is about 200ms.

Have other people seen the same performance behaviour or is this a quirk of my device (S3)? What's the fastest way to fill a byte buffer with unique values?

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline quew8

JGO Coder


Medals: 30



« Reply #1 - Posted 2014-02-02 19:21:04 »

In Android, I recommend just using the built in Bitmap class, which you can use to fill a OpenGL texture using the GLUtils helper class. (I think it's GLUtils, it might be something slightly different)
Offline EgonOlsen
« Reply #2 - Posted 2014-02-02 19:44:40 »

That's normal behaviour on Android. The fastest way without going native is to put arrays instead of single values. They don't have to be the size of the data, a reasonable sized temp buffer will do.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #3 - Posted 2014-02-03 04:40:38 »

Hmm. That's annoying. Because right now I've got 20 sprite objects, and simply generating their vertices and packing them into a ByteBuffer is running at 18fps. The same code happily runs 8k sprites at 60fps on my several years old MacBook Pro.

Surely Android isn't this bad? I must be doing something wrong somewhere...

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline EgonOlsen
« Reply #4 - Posted 2014-02-03 07:08:57 »

And you are doing this every frame?

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #5 - Posted 2014-02-03 16:53:18 »

Yeah. I'm using a Bubblemark setup for benchmarking, so all the sprites are moving all the time.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline EgonOlsen
« Reply #6 - Posted 2014-02-03 20:35:20 »

That's a bit strange...i made myself a little test case and my Nexus 4 can render up to 66 individual instances of a 1089 vertices mesh at that frame rate (http://jpct.de/pix/many_wizards.png), all animated each frame which means ~71.000 updated vertices (plus ~71.000 normals...) each frame.

Which device are you testing this on?

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #7 - Posted 2014-02-03 21:31:05 »

Gnn. Just found out that when run normally on the phone (an S4) it runs at 60fps. Only when running with Eclipse attached is it super slow.

That's particularly annoying since I had a very similar issue with my previous phone (an S2) and a different dev environment setup over a year ago and never found the root cause of it.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline EgonOlsen
« Reply #8 - Posted 2014-02-03 21:58:35 »

I never experienced that with any device. Are you running it in some kind of debug or tracking mode?

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #9 - Posted 2014-02-03 23:27:43 »

Just the usual debug via Eclipse and usb debugging. No funny settings on the developer options as far as I can tell.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline EgonOlsen
« Reply #10 - Posted 2014-02-04 06:35:26 »

Maybe it's a issue with the USB connection itself. Maybe the port is running in 1.1 mode or something like this. This can happen because of faulty cables or components that are violating the USB specs. I would try to connect the device directly without using a hub or use another port...just to be sure.

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #11 - Posted 2014-02-04 08:04:10 »

Hmm, that is another possibility I've not thought of before. This is plugged direct into my macbook - i wonder if there's somewhere that will tell me what speed it's running at.

I don't have a spare cable to hand right now, but I'll certainly give that a try when I can. Thanks.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline Nate

JGO Kernel


Medals: 149
Projects: 4
Exp: 14 years


Esoteric Software


« Reply #12 - Posted 2014-02-04 19:22:38 »

This is standard behavior. Running on a device with the debugger attached is waaaaay slow. I thought you learned this last time? Tongue It is true for all devices. Either run with the Run button, not Debug, or disconnect the debugger after running. Eclipse has some settings that will automatically run in debug even if you press Run, eg if you have a breakpoint set, so keep an eye on it.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (37 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (42 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (61 views)
2014-09-21 02:42:18

BurntPizza (30 views)
2014-09-21 01:30:30

moogie (36 views)
2014-09-21 00:26:15

UprightPath (49 views)
2014-09-20 20:14:06

BurntPizza (52 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!