Forum Multiplayer Serious resource allocation problem with send message

Discussion and help relating to the PlayerIO Multiplayer API.

Serious resource allocation problem with send message

Postby robertflesch » December 4th, 2017, 7:59 pm

I was running adobe scout on my app this weekend. My target framerate is 60 fps.

I started noticing garbage collection spikes once a second.
I traced this back to Connection.sendMessage.
Each time I call sendMessage the send message call performs 27 memory allocations, which account for 98KB of memory.
This is to send a simple 32 character guid and 6 numbers. Ideally I would send 3 of these per second.

I get a similar hit on memory whenever I receive one of these calls.

This is a fatal roadblock for me. At this time I can see a few options.
1) Player.io rewrites the network connection layer to optimize memory allocations
2) Player.io lets me rewrite the connection layer to optimize memory allocations
3) Player.io open sources the network layer ( which will let me do #2 )
4) Move to a different backend.

Thoughts?

After writing this I made a change to how I compose messages.
It helps, but not enough.
// This style does 10 allocations for 27KB of memory
Code: Select all
static private function sourceMovementEvent( event:ModelEvent ):void {
    var msg:Message = _connection.createMessage( MOVE_MESSAGE );
    var ba:ByteArray = new ByteArray();
    ba.writeUTFBytes( Player.player.instanceGuid );
    ba.writeFloat( event.position.x );
    ba.writeFloat( event.position.y );
    ba.writeFloat( event.position.z );
    ba.writeFloat( event.rotation.x );
    ba.writeFloat( event.rotation.y );
    ba.writeFloat( event.rotation.z );
    msg.add( ba );
    _connection.sendMessage( msg );
}


// The suggested style does 27 allocations for a total of 98KB of memory
Code: Select all
static private function sourceMovementEvent( event:ModelEvent ):void {
    var msg:Message = _connection.createMessage( MOVE_MESSAGE );
    msg.add( Player.player.instanceGuid );
    msg.add( event.position.x, event.position.y, event.position.z );
    msg.add( event.rotation.x, event.rotation.y, event.rotation.z );
    _connection.sendMessage( msg );
}

Scout screen capture.
https://imgur.com/a/vCjRS

Henrik, why not open source the network layer for as3? It can only get better.
robertflesch
Paid Member
 
Posts: 136
Joined: April 22nd, 2013, 9:18 pm

Return to Multiplayer



cron