Can we reduce the GC allocations in BitSwarmClient?

Post here your questions about the Unity / .Net / Mono / Windows 8 / Windows Phone 8 API for SFS2X

Moderators: Lapo, Bax

User avatar
AndyMartin458
Posts: 55
Joined: 15 May 2012, 21:57

Can we reduce the GC allocations in BitSwarmClient?

Postby AndyMartin458 » 27 Jan 2015, 08:26

I am sending the transform of my player, and it is generating quite a bit of Garbage (memory that was allocated with new and then discarded). Is there something that could possibly be fixed in the SFSProtoclCodec.OnPacketWrite() to reduce how much garbage is generated? I've attached the picture from the profiler along with my code that is generating the call.

This is the code that is filling the SFS object so that you can know what I'm sending. :shock:

Code: Select all

public void FillSFSObject(ISFSObject data)
{
    m_TransformToSend[0] = Convert.ToDouble(this.m_Position.x);
    m_TransformToSend[1] = Convert.ToDouble(this.m_Position.y);
    m_TransformToSend[2] = Convert.ToDouble(this.m_Position.z);
    m_TransformToSend[3] = Convert.ToDouble(this.m_AngleRotation.x);
    m_TransformToSend[4] = Convert.ToDouble(this.m_AngleRotation.y);
    m_TransformToSend[5] = Convert.ToDouble(this.m_AngleRotation.z);
       
    data.PutDoubleArray("transform", m_TransformToSend);
    data.PutLong("t", Convert.ToInt64(this.m_TimeStamp));
}

//The current location of your player
public void SendTransform(ISFSObject data)
{
    Room room = smartFox.LastJoinedRoom;
     
    // True flag = UDP
    if(smartFox.UdpInited)
    {
        ExtensionRequest request = new ExtensionRequest(SEND_TRANSFORM, data, room, true);
        smartFox.Send(request);
    }
}
Attachments
Capture.PNG
Profiler image to pinpoint the cause of the garbage colleciton.
(148.11 KiB) Not downloaded yet
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Can we reduce the GC allocations in BitSwarmClient?

Postby Lapo » 27 Jan 2015, 09:23

Hi,
we're talking about ~60Kb of memory, not 60MB :)
I mean 60Kb should really be of no concern.

The method creates 1 single local variable which is then passed down to the rest of the network pipeline. If you remove that nothing will work.
Lapo
--
gotoAndPlay()
...addicted to flash games
immagitchu
Posts: 7
Joined: 27 May 2018, 10:16

Re: Can we reduce the GC allocations in BitSwarmClient?

Postby immagitchu » 27 May 2018, 11:20

Hello! As far as I understand, we are having quiet the same issue, only not with sending data, but receiving it. We are working on MOBA game project and client receives player positions data 25 times per second from server (I guess it is usual practice). And it causes allocation up to 100 KB per frame. As a result we have too much memory allocated till the moment it gets collected with garbage collector (smth about 50 MB). It causes freezes not only on slow devices but powerful ones too.

We tried to check data we are sending and the way we deal with it and we noticed that even if we send just empty object and do nothing with it on client side, the situation with memory is the same.

Are we doing something wrong? Is there any way to reduce allocations in our case?

Thanks in advance for any help with the issue.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Can we reduce the GC allocations in BitSwarmClient?

Postby Lapo » 28 May 2018, 07:23

Hi,
can you confirm you're using the most up to date version of the API?
I ask because this is a 3+ years old post and we've already optimized GC related aspects on multiple releases.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
immagitchu
Posts: 7
Joined: 27 May 2018, 10:16

Re: Can we reduce the GC allocations in BitSwarmClient?

Postby immagitchu » 28 May 2018, 12:39

We are using SmartFoxServer 2X 2.13.1.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Can we reduce the GC allocations in BitSwarmClient?

Postby Lapo » 28 May 2018, 13:18

immagitchu wrote:We are using SmartFoxServer 2X 2.13.1.

Okay, but I suppose your complaint about the GC is related to the client side. So the question is: are you using the latest available API?
If in doubt check the download page here:
https://www.smartfoxserver.com/download/sfs2x#p=client

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
immagitchu
Posts: 7
Joined: 27 May 2018, 10:16

Re: Can we reduce the GC allocations in BitSwarmClient?

Postby immagitchu » 28 May 2018, 14:13

We are using version 1.7.6. It is the newest available for Unity as far as I can see.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Can we reduce the GC allocations in BitSwarmClient?

Postby Lapo » 29 May 2018, 07:59

Thanks.
I am not sure how it is possible that 100KB of data can be allocated per frame, by the SFS API.

How did you come up with this number?
We tried to check data we are sending and the way we deal with it and we noticed that even if we send just empty object and do nothing with it on client side, the situation with memory is the same.

Can you send us a proof of concept that demonstrates this issue?
You can send it directly to our support@... mailbox. (With a reference to this topic)

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
immagitchu
Posts: 7
Joined: 27 May 2018, 10:16

Re: Can we reduce the GC allocations in BitSwarmClient?

Postby immagitchu » 31 May 2018, 16:28

Can you please specify support email address? Cause I can't find it anywhere, sorry...
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Can we reduce the GC allocations in BitSwarmClient?

Postby Lapo » 01 Jun 2018, 07:21

Hi,
by support@... I mean [at]smartfoxserver.com

We usually don't write the whole address in a message because they get detected by spam bots which use them to send junk emails :)

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
immagitchu
Posts: 7
Joined: 27 May 2018, 10:16

Re: Can we reduce the GC allocations in BitSwarmClient?

Postby immagitchu » 01 Jun 2018, 07:45

I see :) Well, actually after I wrote post, I found where to send email. I added simple project that demonstrates issue and video with profiling. I hope that you have received it.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Can we reduce the GC allocations in BitSwarmClient?

Postby Lapo » 01 Jun 2018, 08:44

No, we have not received it so far.
Maybe it's still on its way? :)
Lapo

--

gotoAndPlay()

...addicted to flash games
immagitchu
Posts: 7
Joined: 27 May 2018, 10:16

Re: Can we reduce the GC allocations in BitSwarmClient?

Postby immagitchu » 01 Jun 2018, 09:03

That is strange, cause I've sent it twice already. Maybe you have another channel to contact you? Maybe you can write me in private messages in which other way I can send you files?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Can we reduce the GC allocations in BitSwarmClient?

Postby Lapo » 01 Jun 2018, 10:26

We received the 2nd email, thanks.
We'll get back to you as soon as possible.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
immagitchu
Posts: 7
Joined: 27 May 2018, 10:16

Re: Can we reduce the GC allocations in BitSwarmClient?

Postby immagitchu » 01 Jun 2018, 19:42

I have received answer from your support email but it doesn't really include reference to my test project and only to unity itself. Please, check another letter I've sent you.

Return to “SFS2X C# API”

Who is online

Users browsing this forum: No registered users and 28 guests