[HTML5] Dead Code Elimination

Joshua said this doesn't work, and I verified that it doesn't. Given that the HTML5 output can be rather large without this, this is a pretty important one to get working if possible. For the record, I triggered it by sticking this in my NMML file. …

Viewing 1 to 14 (14 Total)
[HTML5] Dead Code Elimination

Jon

Jon
Total Posts: 272
Joined: March 08, 2012

Joshua said this doesn't work, and I verified that it doesn't. Given that the HTML5 output can be rather large without this, this is a pretty important one to get working if possible.

For the record, I triggered it by sticking this in my NMML file.

Edit: Looks like it trimmed out my tag. Hmm..

Tags:
Posted on May 21, 2012 at 1:04 AM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: [HTML5] Dead Code Elimination

Agreed -- I'm not sure what breaks, but it would be nice to crunch the file size down with DCE.

I believe you can also use (or at least try) --js-modern, which (I believe) also reduces the output file size.

Unless there are good reasons not to, I think it may make sense to use --js-modern by default in both the HTML5 templates, and to use --dead-code-elimination in the release template once we figure out what's causing it to break

Posted on May 21, 2012 at 1:46 AM

Jon

Jon
Total Posts: 272
Joined: March 08, 2012

Re: [HTML5] Dead Code Elimination

Thanks, I'll give that a try and let you know how much of a savings it represents.

Posted on May 21, 2012 at 1:12 PM

grumpytoad

grumpytoad
Total Posts: 63
Joined: November 21, 2011

Re: [HTML5] Dead Code Elimination

I'm not sure I've ever seen it fail...

Posted on May 22, 2012 at 1:51 PM

Jon

Jon
Total Posts: 272
Joined: March 08, 2012

Re: [HTML5] Dead Code Elimination

To be clear, failure in this case means that it does output something, but the game errors out immediately.

Posted on May 22, 2012 at 3:34 PM

grumpytoad

grumpytoad
Total Posts: 63
Joined: November 21, 2011

Re: [HTML5] Dead Code Elimination

if you have an example where this is happening, that'd help - please provide some version numbers too, as this feature has changed a little in haxe's repository in recent months.

Posted on May 22, 2012 at 4:02 PM

Jon

Jon
Total Posts: 272
Joined: March 08, 2012

Re: [HTML5] Dead Code Elimination

Is --js-modern a new flag? It's flagging it as an unknown option for me.

My bad on the error - it's actually the other way around. It starts choking on my code.

Specifically, it chokes on Box2D.

[LOG] <COMMAND> /Users/jon/Desktop/nme/plaf/haxe/lib/box2d/1,11/box2D/dynamics/contacts/B2PolyAndEdgeContact.hx:35: lines 35-372 : Field evaluate is declared 'override' but doesn't override any field
[LOG] <COMMAND> /Users/jon/Desktop/nme/plaf/haxe/lib/box2d/1,11/box2D/dynamics/contacts/B2EdgeAndCircleContact.hx:34: lines 34-173 : Field evaluate is declared 'override' but doesn't override any field
[LOG] <COMMAND> /Users/jon/Desktop/nme/plaf/haxe/lib/box2d/1,11/box2D/dynamics/contacts/B2PolygonContact.hx:31: lines 31-57 : Field evaluate is declared 'override' but doesn't override any field
[LOG] <COMMAND> /Users/jon/Desktop/nme/plaf/haxe/lib/box2d/1,11/box2D/dynamics/contacts/B2PolyAndCircleContact.hx:34: lines 34-57 : Field evaluate is declared 'override' but doesn't override any field
[LOG] <COMMAND> /Users/jon/Desktop/nme/plaf/haxe/lib/box2d/1,11/box2D/dynamics/contacts/B2CircleContact.hx:31: lines 31-55 : Field evaluate is declared 'override' but doesn't override any field

It chokes on some of my classes too and claims the following, but those statements are not true. They definitely have constructors.

[LOG] <COMMAND> /Users/jon/Desktop/nme/plaf/haxe/lib/gamelib/1,00/com/test/io/TilesetReader.hx:29: characters 21-119 : com.test.models.scene.Tileset does not have a constructor
[LOG] <COMMAND> /Users/jon/Desktop/nme/plaf/haxe/lib/gamelib/1,00/com/test/io/TilesetReader.hx:71: characters 9-75 : com.test.models.scene.Tile does not have a constructor
[LOG] <COMMAND> /Users/jon/Desktop/nme/plaf/haxe/lib/gamelib/1,00/com/test/io/TilesetReader.hx:39: lines 39-72 : com.test.models.scene.Tile should be Void

It seems to me that the problem is that dead code eliminator might be a little stricter about syntax than the regular compiler perhaps?

I'm using 3.3.0.

Posted on May 22, 2012 at 11:01 PM

grumpytoad

grumpytoad
Total Posts: 63
Joined: November 21, 2011

Re: [HTML5] Dead Code Elimination

What haxe version are you using? DCE doesn't like static initializer code, because it is over eager in this case and removes code that you actually need.

box2d is known not to run DCE - the port hasn't been maintained for some time (years), and I know there are a number of splinter ports, which might contain the fixes you need, but also risk being less compatible. Another option is using nape - it's certainly being kept up to date more often. I haven't tried it though, so cannot say if it'll work on haxe's js output.

Posted on May 23, 2012 at 12:10 AM

Jon

Jon
Total Posts: 272
Joined: March 08, 2012

Re: [HTML5] Dead Code Elimination

I have 2.08.

Is there a newer Box2D port? This one is pretty current (from the perspective of being synced up with the latest from the original Box2D) and whatever haxelib itself is hosting.

I really like Nape (and it demolishes Box2D in performance on desktop), but its mobile performance was a non-starter for me, and it doesn't look like something that's going to be addressed anytime soon. I'm actually porting over a large amount of code from AS3 and am pretty vested in sticking to Box2D for that reason.

Posted on May 23, 2012 at 12:32 AM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: [HTML5] Dead Code Elimination

The port for Box2D was pretty old, so I created a new port, based on Box2DFlash 2.1a

It was last updated 4 months ago, and is on GitHub athttp://www.github.com/jgranick/box2d.... If there are any patches, fixes or other improvements for the library, I welcome any help or pull requests to make it better. I've started to explore a native Box2D extension, but there are still some nuances to making that work that I still need to work out. Hugh has helped give me pointers, so I think know what I need to do, but I am trying to do it using the BuildHX tool, so it is taking a little more time.

Especially since Box2D has a relatively large number of classes, methods and properties, I would like to try and devise a system that can wrap the native library in Haxe that is fully automated. This makes the task a bit more complex, but will open the door for supporting other native libraries as well. If we can finish that work, perhaps that will be the best of both worlds -- the same API, but improved native performance.

I can already create native class instances and make calls on them, but getting class instances as the return values is something I need to work out. I also haven't implemented arrays yet, but that shouldn't be too terrible.

Posted on May 23, 2012 at 12:46 AM

Jon

Jon
Total Posts: 272
Joined: March 08, 2012

Re: [HTML5] Dead Code Elimination

By native extension, you mean that this is targeted towards just the CPP target I assume, and for Flash and HTML5, it'll continue to use the original port, or something to that effect? That would be ideal for performance and usability.

I'll look into that newer port and get back to you - I'm actually to the point where I'm going to deep dive into Box2D this week. The rest of things are looking good for the most part.

To my eye, even the "older" port seemed fairly fresh to me API wise and didn't stick out to me as old. The only truly old port I ever saw was the one I got from the BigBlocks founder / dev which was based off Box2D 1.4.

Posted on May 23, 2012 at 1:04 AM

singmajesty

singmajesty
Total Posts: 2140
Joined: August 25, 2011

Re: [HTML5] Dead Code Elimination

The Box2D that I have on GitHub is the one that's in haxelib as "box2d"

I'm trying to see if its possible to wrap the native library without altering the API. In order to make things work, you need to keep a native "handle" so you have the "real" object in C++, and the Haxe class that wraps it. The tricky part is when you need to convert a native handle into a Haxe instance.

Anyway, that would be the ideal -- a compatible library for C++, so you can still use the same API for all platforms

Posted on May 23, 2012 at 1:11 AM

grumpytoad

grumpytoad
Total Posts: 63
Joined: November 21, 2011

Re: [HTML5] Dead Code Elimination

The only box2dhx I have managed to get to work reliably on html5 ishttp://box2dhx.googlecode.com/svn/trunk... the last commit is dated 2010-01-13... YMMV depending on what you are compiling. I don't think any haxe-compatible physics library exists yet that is well optimised for javascript.

P.S. DCE has changed significantly between haxe-2.08 and 2.09

Posted on May 23, 2012 at 6:36 AM

Jon

Jon
Total Posts: 272
Joined: March 08, 2012

Re: [HTML5] Dead Code Elimination

Aye, that is similar to the one that Michael (BigblockGames) gave me. He optimized it a bit to reduce object creations for his Goblin War Machine game. I'd happily settle for that take if it weren't for the fact that I use some of the newer Box2D features rather extensively (edge shapes in particular)

Posted on May 23, 2012 at 12:35 PM