Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone: Which are the most useful techniques for faster Bluetooth?

I'm adding peer-to-peer bluetooth using GameKit to an iPhone shoot-em-up, so speed is vital. I'm sending about 40 messages a second each way, most of them with the faster GKSendDataUnreliable, all serializing with NSCoding. In testing between a 3G and 3GS, this is slowing the 3G down a lot more than I'd like. I'm wondering where I should concentrate my efforts to speed it up.

How much slower is GKSendDataReliable? For the few packets that have to get there, would it be faster to send a GKSendDataUnreliable and have the peer send an acknowledgement so I can send again if I don't get the Ack within, say, 100ms?

How much faster would it be to create the NSData instance using a regular C array rather than archiving with the NSCoding protocol? Is this serialization process (for about a dozen floats) just as slow as you'd expect from an object creation/deallocation overhead, or is something particularly slow happening?

I heard that (for example) sending four seperate sets of data is much, much slower, than sending one piece of data four times the size. Would I make a significant saving by sending separate packets of data that wouldn't always go together in the same packet when they happen at the same time?

Are there any other bluetooth performance secrets I've missed?

Thanks for your help.

like image 353
DenverCoder9 Avatar asked Jun 14 '10 14:06

DenverCoder9


1 Answers

I'm not a bluetooth expert, but in general sending data using reliable is 1.5x the speed of sending data unreliable. I would avoid trying to send an ACK back using an unreliable method because then you're going to have to put in all kinds of ridiculous logic to detect whether the ACK failed to arrive which will slow you down much more than just using a reliable send.

Sending data has a high latency which means that sending 4 small packets is going to take more time than sending 1 packet with a 4x sized payload. Any time you can increase the payload size to make fewer sends you will get a performance benefit.

If you know the size and shape of the data that you are sending and receiving, you can also squeeze out some performance by sending byte arrays or arrays of numbers rather than using NSCoding because the NSCoding is going to consume some time to serialize and de-serialize (a step you can skip if you're just sending arrays) and the amount of data you send will be slightly more with NSCoder than it would be with a raw array.

like image 78
Kevin Hoffman Avatar answered Nov 15 '22 15:11

Kevin Hoffman