<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Improving C#/Mono for Games</title>
	<atom:link href="http://aras-p.info/blog/2009/11/14/improving-cmono-for-games/feed/" rel="self" type="application/rss+xml" />
	<link>http://aras-p.info/blog/2009/11/14/improving-cmono-for-games/</link>
	<description>Random thoughts of a triangle pusher</description>
	<lastBuildDate>Thu, 09 Feb 2012 07:56:51 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: bobDole</title>
		<link>http://aras-p.info/blog/2009/11/14/improving-cmono-for-games/comment-page-1/#comment-25036</link>
		<dc:creator>bobDole</dc:creator>
		<pubDate>Tue, 12 Jan 2010 21:36:05 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=442#comment-25036</guid>
		<description>This is not a put down on Aras but he seems to deal with a lot of low-level hacky stuff. Which probably has a big impact on iphone but a lot less on a computer. I generally agree with kenpex c# uses a different programming model. 

That said in theory being able to limit the duration of a GC call sounds like a good idea. While removing GC seems less optimal.</description>
		<content:encoded><![CDATA[<p>This is not a put down on Aras but he seems to deal with a lot of low-level hacky stuff. Which probably has a big impact on iphone but a lot less on a computer. I generally agree with kenpex c# uses a different programming model. </p>
<p>That said in theory being able to limit the duration of a GC call sounds like a good idea. While removing GC seems less optimal.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kenpex</title>
		<link>http://aras-p.info/blog/2009/11/14/improving-cmono-for-games/comment-page-1/#comment-22847</link>
		<dc:creator>kenpex</dc:creator>
		<pubDate>Sun, 15 Nov 2009 20:24:14 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=442#comment-22847</guid>
		<description>I have to say, of course we&#039;ll all like a better GC. 

But that is a not a big deal as it might seem or at least, it&#039;s not that worse than manual memory management.

I can already see so many programmers looking at that graph and thinking that they&#039;re indeed right when they think that GC sucks and C/C++ memory management is the key...

I don&#039;t think you&#039;re right when you say that not allocating in runtime makes GC not useful. GC is NOT a tool to avoid memory leaks, is NOT a tool for lazy programmers that do not want to write a free here and there. In fact, even in C those problems are not problems, with a good debugging malloc leaks are an easy bug to solve (fragmentation is the real bitch).

GC is to make objects live across modules possible. In C++ in order to do that you write a RC system, and 99% of the games do that. GC is better than RC at solving that problem, that&#039;s his strength, not the leaks thing...

As for the runtime cost... It can be high, but it&#039;s important to note that even manual memory allocation/deallocation cost is high, and games usually avoid dynamic allocations in runtime, even without GC! That said, the situation is even worse, if you factor in the RC time, that as I said, most games use...

So in summary... GC has an overhead in runtime? True, but who cares, memory management overhead is anyway too high and unpredictable even without GC. What&#039;s the advantage of GC then? It&#039;s a better RC system! Why moving GC are cool? Mostly because you can avoid fragmentation, that&#039;s the real problem!</description>
		<content:encoded><![CDATA[<p>I have to say, of course we&#8217;ll all like a better GC. </p>
<p>But that is a not a big deal as it might seem or at least, it&#8217;s not that worse than manual memory management.</p>
<p>I can already see so many programmers looking at that graph and thinking that they&#8217;re indeed right when they think that GC sucks and C/C++ memory management is the key&#8230;</p>
<p>I don&#8217;t think you&#8217;re right when you say that not allocating in runtime makes GC not useful. GC is NOT a tool to avoid memory leaks, is NOT a tool for lazy programmers that do not want to write a free here and there. In fact, even in C those problems are not problems, with a good debugging malloc leaks are an easy bug to solve (fragmentation is the real bitch).</p>
<p>GC is to make objects live across modules possible. In C++ in order to do that you write a RC system, and 99% of the games do that. GC is better than RC at solving that problem, that&#8217;s his strength, not the leaks thing&#8230;</p>
<p>As for the runtime cost&#8230; It can be high, but it&#8217;s important to note that even manual memory allocation/deallocation cost is high, and games usually avoid dynamic allocations in runtime, even without GC! That said, the situation is even worse, if you factor in the RC time, that as I said, most games use&#8230;</p>
<p>So in summary&#8230; GC has an overhead in runtime? True, but who cares, memory management overhead is anyway too high and unpredictable even without GC. What&#8217;s the advantage of GC then? It&#8217;s a better RC system! Why moving GC are cool? Mostly because you can avoid fragmentation, that&#8217;s the real problem!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pat</title>
		<link>http://aras-p.info/blog/2009/11/14/improving-cmono-for-games/comment-page-1/#comment-22846</link>
		<dc:creator>Pat</dc:creator>
		<pubDate>Sun, 15 Nov 2009 17:14:39 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=442#comment-22846</guid>
		<description>I still disagree on the GC extensions. I think the GC is what it is, and it works fine for many cases. Aras mentioned object pooling in the original post, and that is a great solution, especially for composition-based stuff. Instead of suggesting to the .NET runtime how we may like garbage collection to occur, I think the GC is just an uncontrolled element that is part of the environment. If we want to assert more control over it, I think the problem should be implemented at the application level, not the runtime. In my opinion, wanting hacks into the runtime for GC control is like wanting Microsoft to provide malloc hooks in their C runtime. We could either ask for the malloc hooks, or just code accordingly, and have our own hooks. Or it&#039;s like using a micro-allocator for small, temporary allocations. The GC seems no different to me. This is non-desired, default, memory functionality...so we write our own code to perform the specific task in a more optimal way. 

Than again, I am a C programmer, and write C# like C++, and when all you have is a hammer, everything looks like a nail.</description>
		<content:encoded><![CDATA[<p>I still disagree on the GC extensions. I think the GC is what it is, and it works fine for many cases. Aras mentioned object pooling in the original post, and that is a great solution, especially for composition-based stuff. Instead of suggesting to the .NET runtime how we may like garbage collection to occur, I think the GC is just an uncontrolled element that is part of the environment. If we want to assert more control over it, I think the problem should be implemented at the application level, not the runtime. In my opinion, wanting hacks into the runtime for GC control is like wanting Microsoft to provide malloc hooks in their C runtime. We could either ask for the malloc hooks, or just code accordingly, and have our own hooks. Or it&#8217;s like using a micro-allocator for small, temporary allocations. The GC seems no different to me. This is non-desired, default, memory functionality&#8230;so we write our own code to perform the specific task in a more optimal way. </p>
<p>Than again, I am a C programmer, and write C# like C++, and when all you have is a hammer, everything looks like a nail.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Miguel de Icaza</title>
		<link>http://aras-p.info/blog/2009/11/14/improving-cmono-for-games/comment-page-1/#comment-22845</link>
		<dc:creator>Miguel de Icaza</dc:creator>
		<pubDate>Sun, 15 Nov 2009 17:02:51 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=442#comment-22845</guid>
		<description>Python&#039;s embeddable runtime is half the size of Mono&#039;s embeddable runtime (1.2 megs vs 2.4 megs).   In Python&#039;s case there is no JIT engine, although there are separate independent projects that provide JIT engines (Jython, IronPython, PyPy).

The other difference is that Python remains a dynamic language at its core, so even with JIT engines they do not match the performance of statically compiled languages like C# or UnityScript.</description>
		<content:encoded><![CDATA[<p>Python&#8217;s embeddable runtime is half the size of Mono&#8217;s embeddable runtime (1.2 megs vs 2.4 megs).   In Python&#8217;s case there is no JIT engine, although there are separate independent projects that provide JIT engines (Jython, IronPython, PyPy).</p>
<p>The other difference is that Python remains a dynamic language at its core, so even with JIT engines they do not match the performance of statically compiled languages like C# or UnityScript.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aras Pranckevičius</title>
		<link>http://aras-p.info/blog/2009/11/14/improving-cmono-for-games/comment-page-1/#comment-22843</link>
		<dc:creator>Aras Pranckevičius</dc:creator>
		<pubDate>Sun, 15 Nov 2009 15:22:58 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=442#comment-22843</guid>
		<description>@steve: before Unity 1.0, they used Python. This was way before I joined, but some of the reasons why they switched to Mono: 1) speed, 2) much better embedding, 3) size. Of course all that was around 2003-2004, so everything might have changed since then. Do you know what&#039;s Python&#039;s embedding size?</description>
		<content:encoded><![CDATA[<p>@steve: before Unity 1.0, they used Python. This was way before I joined, but some of the reasons why they switched to Mono: 1) speed, 2) much better embedding, 3) size. Of course all that was around 2003-2004, so everything might have changed since then. Do you know what&#8217;s Python&#8217;s embedding size?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Martin</title>
		<link>http://aras-p.info/blog/2009/11/14/improving-cmono-for-games/comment-page-1/#comment-22840</link>
		<dc:creator>Sam Martin</dc:creator>
		<pubDate>Sun, 15 Nov 2009 12:30:13 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=442#comment-22840</guid>
		<description>@aras. Some nice points. Spiky garbage collection is a real problem in all GC&#039;d languages I can think of. I&#039;m not even sure there is a GC&#039;d language that doesn&#039;t suffer from it?

@Steve I thought quite a few people are using python now? Probably not as many as Lua, but then again Lua is utterly trivial to integrate and get up and running. I haven&#039;t used much python myself, but the usual complaints I here are:
- tricky/time consuming to get properly integrated
- has some nasty performance cases
Are these fair? Is mono easier or better in these regards?</description>
		<content:encoded><![CDATA[<p>@aras. Some nice points. Spiky garbage collection is a real problem in all GC&#8217;d languages I can think of. I&#8217;m not even sure there is a GC&#8217;d language that doesn&#8217;t suffer from it?</p>
<p>@Steve I thought quite a few people are using python now? Probably not as many as Lua, but then again Lua is utterly trivial to integrate and get up and running. I haven&#8217;t used much python myself, but the usual complaints I here are:<br />
- tricky/time consuming to get properly integrated<br />
- has some nasty performance cases<br />
Are these fair? Is mono easier or better in these regards?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: steve</title>
		<link>http://aras-p.info/blog/2009/11/14/improving-cmono-for-games/comment-page-1/#comment-22839</link>
		<dc:creator>steve</dc:creator>
		<pubDate>Sun, 15 Nov 2009 11:45:03 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=442#comment-22839</guid>
		<description>I don&#039;t understand why more people don&#039;t use Python. It&#039;s small, cross-platform, has built-in JIT (rather than an add-on like in Lua), garbage collector is pretty controllable (can be turned on and off and invoked directly).

I must admit that I&#039;m still not hugely fond of Python&#039;s fixed source tabulation, but I can live with that given how much more mature and packed with features it is than so many alternatives.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t understand why more people don&#8217;t use Python. It&#8217;s small, cross-platform, has built-in JIT (rather than an add-on like in Lua), garbage collector is pretty controllable (can be turned on and off and invoked directly).</p>
<p>I must admit that I&#8217;m still not hugely fond of Python&#8217;s fixed source tabulation, but I can live with that given how much more mature and packed with features it is than so many alternatives.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aras Pranckevičius</title>
		<link>http://aras-p.info/blog/2009/11/14/improving-cmono-for-games/comment-page-1/#comment-22835</link>
		<dc:creator>Aras Pranckevičius</dc:creator>
		<pubDate>Sun, 15 Nov 2009 07:32:13 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=442#comment-22835</guid>
		<description>@Miguel: all very valid points. I am aware that you have moved a lot to reduce distribution size for Moonlight etc. I&#039;ve updated my post to clarify that some of my observations are based on old stuff.</description>
		<content:encoded><![CDATA[<p>@Miguel: all very valid points. I am aware that you have moved a lot to reduce distribution size for Moonlight etc. I&#8217;ve updated my post to clarify that some of my observations are based on old stuff.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ReJ</title>
		<link>http://aras-p.info/blog/2009/11/14/improving-cmono-for-games/comment-page-1/#comment-22833</link>
		<dc:creator>ReJ</dc:creator>
		<pubDate>Sun, 15 Nov 2009 03:39:15 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=442#comment-22833</guid>
		<description>Regarding GC fix #2: right now we have 2 lifetime &quot;types&quot; of the objects - on-stack structs (lifetime is equal to the scope of the function) or GC managed objects with arbitrary lifetime. That is OK for generic applications, however games usually have a lot of objects which lifetime is longer than scope of a single function, but shorter than single frame - events, temporary buffers which gather and retain data until it is processed (for example rendered) during the course of a frame, callbacks arguments, etc.

I think it would be rather nice extension - possibility to allocate objects with &quot;single frame&quot; lifetime - collection then would be a simple pointer move at the end of the frame.

However protecting user from accessing destroyed object during the next frame could be tricky (at least with BoehmGC) - most probably that would require usage of proxy pointers or objects would have to store &quot;timestamps&quot; for sanity checks.</description>
		<content:encoded><![CDATA[<p>Regarding GC fix #2: right now we have 2 lifetime &#8220;types&#8221; of the objects &#8211; on-stack structs (lifetime is equal to the scope of the function) or GC managed objects with arbitrary lifetime. That is OK for generic applications, however games usually have a lot of objects which lifetime is longer than scope of a single function, but shorter than single frame &#8211; events, temporary buffers which gather and retain data until it is processed (for example rendered) during the course of a frame, callbacks arguments, etc.</p>
<p>I think it would be rather nice extension &#8211; possibility to allocate objects with &#8220;single frame&#8221; lifetime &#8211; collection then would be a simple pointer move at the end of the frame.</p>
<p>However protecting user from accessing destroyed object during the next frame could be tricky (at least with BoehmGC) &#8211; most probably that would require usage of proxy pointers or objects would have to store &#8220;timestamps&#8221; for sanity checks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pat</title>
		<link>http://aras-p.info/blog/2009/11/14/improving-cmono-for-games/comment-page-1/#comment-22824</link>
		<dc:creator>Pat</dc:creator>
		<pubDate>Sat, 14 Nov 2009 21:34:12 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=442#comment-22824</guid>
		<description>While I agree in principle about the garbage collector problems, I disagree that the tools do not exist already to work around some of the GC issues. The GC is only something of a black-box, but it is not entirely opaque. Unless Unity performs much differently, there should be a pattern to the GC operations, and what is triggering them. In my opinion, solving the problem at that level is a much better approach than trying to bypass the GC via a Mono extension. 

You should be able to do arrays without copying by either allocating a chunk of memory from the GC, or by allocating an array, pinning it, and using &#039;UnsafeAddrOfPinnedArrayElement&#039;. I have been using the second method but I haven&#039;t done performance measurements. I could be totally wrong.

I spent a significant chunk of time putting the .NET/C interop stuff through its paces about a few months ago, and my findings were that there are lots of ways to do it, and many of them are bad to do. Being able to examine the IL code really helps with a lot of things I have found. I have also found that, if the API is causing excessive marshaling time, it may be needed to change the API.</description>
		<content:encoded><![CDATA[<p>While I agree in principle about the garbage collector problems, I disagree that the tools do not exist already to work around some of the GC issues. The GC is only something of a black-box, but it is not entirely opaque. Unless Unity performs much differently, there should be a pattern to the GC operations, and what is triggering them. In my opinion, solving the problem at that level is a much better approach than trying to bypass the GC via a Mono extension. </p>
<p>You should be able to do arrays without copying by either allocating a chunk of memory from the GC, or by allocating an array, pinning it, and using &#8216;UnsafeAddrOfPinnedArrayElement&#8217;. I have been using the second method but I haven&#8217;t done performance measurements. I could be totally wrong.</p>
<p>I spent a significant chunk of time putting the .NET/C interop stuff through its paces about a few months ago, and my findings were that there are lots of ways to do it, and many of them are bad to do. Being able to examine the IL code really helps with a lot of things I have found. I have also found that, if the API is causing excessive marshaling time, it may be needed to change the API.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jedd Haberstro</title>
		<link>http://aras-p.info/blog/2009/11/14/improving-cmono-for-games/comment-page-1/#comment-22823</link>
		<dc:creator>Jedd Haberstro</dc:creator>
		<pubDate>Sat, 14 Nov 2009 21:23:50 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=442#comment-22823</guid>
		<description>There is one thing I think you&#039;re missing: an easy to use tool to expose C++ to Mono. I know you guys have written your own internal tool to do this so it&#039;s not a problem for you, but SWIG generates crap and P/Invoke is just to tedious.</description>
		<content:encoded><![CDATA[<p>There is one thing I think you&#8217;re missing: an easy to use tool to expose C++ to Mono. I know you guys have written your own internal tool to do this so it&#8217;s not a problem for you, but SWIG generates crap and P/Invoke is just to tedious.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Simon</title>
		<link>http://aras-p.info/blog/2009/11/14/improving-cmono-for-games/comment-page-1/#comment-22820</link>
		<dc:creator>Simon</dc:creator>
		<pubDate>Sat, 14 Nov 2009 20:44:24 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=442#comment-22820</guid>
		<description>Good summary. I&#039;m curious; was Lua ever considered for Unity? I always thought they would have been a great fit.</description>
		<content:encoded><![CDATA[<p>Good summary. I&#8217;m curious; was Lua ever considered for Unity? I always thought they would have been a great fit.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Miguel de Icaza</title>
		<link>http://aras-p.info/blog/2009/11/14/improving-cmono-for-games/comment-page-1/#comment-22819</link>
		<dc:creator>Miguel de Icaza</dc:creator>
		<pubDate>Sat, 14 Nov 2009 20:16:53 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=442#comment-22819</guid>
		<description>Aras, you guys keep usih the general purpose Mono which is why you end up with XML an configuration libraries;   I explained to Joe at the GDC earlier this year that you should use the Silverlight profile which has none of these dependencies.   You only have yourself to blame.

As for comparing mono vs lua; they can&#039;t be compared, one is a compiled system the other us an interpreter;   If you want interpreter speeds, by all means use an interpreter and it will be a lot easier to port.

As for the structure representation, yes, there are ways of designing your structures and your marshalling to avoid any conversions.   Send me email or post to mono-devel list and I will be happy to tell you how to do it based on your own structures
Finally, as I have suggested to Lucas and you guys, the silverlight profile has fewer cross dependencies and it works better with the mono linker.  Our linked applications using the generics corlib are smaller than your hand chopped mscorlib and there is still a lot of room for improvement.  The linker is the smarter way of working, as oppossed to the tedious and error prone approach thy you have use so far.   I realize that &quot;we need it fast and we need it today&quot; gets in the way of using the smarter solution, but it has been entirely your choice.

On manual memory mangement: there is a partial solution, you need your objects to implement IDisposable and then call Dispose on them.  It won&#039;t take care of everything, but it will help.   You can also allocate memory manualy using the Marshal class an release it yourself, it is useful in particular for large buffers.

Another trick that you can use to avoid the jittery GC is to enable incremental gc at runtime, I would you to try that and follow up with the results as it seems promising.</description>
		<content:encoded><![CDATA[<p>Aras, you guys keep usih the general purpose Mono which is why you end up with XML an configuration libraries;   I explained to Joe at the GDC earlier this year that you should use the Silverlight profile which has none of these dependencies.   You only have yourself to blame.</p>
<p>As for comparing mono vs lua; they can&#8217;t be compared, one is a compiled system the other us an interpreter;   If you want interpreter speeds, by all means use an interpreter and it will be a lot easier to port.</p>
<p>As for the structure representation, yes, there are ways of designing your structures and your marshalling to avoid any conversions.   Send me email or post to mono-devel list and I will be happy to tell you how to do it based on your own structures<br />
Finally, as I have suggested to Lucas and you guys, the silverlight profile has fewer cross dependencies and it works better with the mono linker.  Our linked applications using the generics corlib are smaller than your hand chopped mscorlib and there is still a lot of room for improvement.  The linker is the smarter way of working, as oppossed to the tedious and error prone approach thy you have use so far.   I realize that &#8220;we need it fast and we need it today&#8221; gets in the way of using the smarter solution, but it has been entirely your choice.</p>
<p>On manual memory mangement: there is a partial solution, you need your objects to implement IDisposable and then call Dispose on them.  It won&#8217;t take care of everything, but it will help.   You can also allocate memory manualy using the Marshal class an release it yourself, it is useful in particular for large buffers.</p>
<p>Another trick that you can use to avoid the jittery GC is to enable incremental gc at runtime, I would you to try that and follow up with the results as it seems promising.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Seon R</title>
		<link>http://aras-p.info/blog/2009/11/14/improving-cmono-for-games/comment-page-1/#comment-22816</link>
		<dc:creator>Seon R</dc:creator>
		<pubDate>Sat, 14 Nov 2009 19:56:09 +0000</pubDate>
		<guid isPermaLink="false">http://aras-p.info/blog/?p=442#comment-22816</guid>
		<description>Interesting read Aras. Explains a bit about what you guys have ahead of you in terms of challenges/frustration in moving Unity to new platforms/consoles.

Keep up the great work!</description>
		<content:encoded><![CDATA[<p>Interesting read Aras. Explains a bit about what you guys have ahead of you in terms of challenges/frustration in moving Unity to new platforms/consoles.</p>
<p>Keep up the great work!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

