crossbridge-community / crossbridge

C/C++ Compiler for the ActionScript Virtual Machine (AVM2)
http://sourceforge.net/projects/crossbridge-community/
Other
151 stars 35 forks source link

Master: Bloated and undebugable SWC #46

Open JoeDupuis opened 10 years ago

JoeDupuis commented 10 years ago

Our games use some SWC produced by Flash CC for vector assets. Since I wasn't able to link those SWC into the SWF produced by CrossBridge (see #45), I outputted the engine as a SWC and link both (the engine SWC and the vector assets SWC) in a flash ide project to output the final SWF (intellij idea, but it does the samething with flash builder). The flash ide project contain just a small main.as to call the entry point of the engine (in the engine SWC).

As soon as I link to my engine's SWC the flash project compilation time spike like crazy. Auto completion is slow and filled with mangled symbol clearly not intended to be used directly by the user of the SWC. Maybe LTO could help by removing unused symbol, I am still experiencing with that, but it slow down the engine dev time like crazy (link time is way higher).

Worse is if I turn debugging symbol at C++ compile time (-g). The flash compiler won't ouput a SWC. It will take 10~20 minutes and crash with a "heap out of memory error" even with a 4096MB heap.

I have a problem similar to this (long as3 compile time and out of memory error) when my C++ code reference to any symbol of the Flash++.h header. I have worked my way around the issue with as3.h and as3++.h, but it would have been great to use the c++ friendlier Flash++.h. It is simply unusable when outputing a SWC instead of a SWF.

In both case the poor performance might be caused by a lack of memory. Maybe it forces the java VM to garbage collect like crazy. I can't tell, because I don't know enough about the inner working of the flash compiler.

I am trying to look into it, but does anybody have a clue as to why it is so slow and take that much memory? Sure it is a fairly big engine, but nothing like the size of unity or similar and yet they seemed to have made it (they killed the project, but it was commercially available for a couple of months).

This issue prevent me from outputting a GDB debuggable SWF for my games since my debuggable engine SWC aren't usable by the flash compiler (only non debug one works). The only way I was able to produce debuggable SWF was directly with crossbridge g++ (instead of outputing a SWC), but this prevent me from linking with my visual & soundfx SWC. (I made a separated issue for this #45)

vpmedia commented 10 years ago

Hi, Please make a simple example if you've time, presenting the problem, it would help to outline some idea to fix the issue (also if you know how to implement this feature, please share it). I'm not an experienced CPP/C developer, so 99% of my changes were not related to the core CrossBridge source code, I've just heavily refactored the structure and build process. Also fixed a lot of cross-platform build issues. So I'm not really familiar with GCC/LLVM to easily implement this myself.

vpmedia commented 10 years ago

My first idea would be to use an external tool to produce ABC from SWF (extracted from SWC), like this one: https://github.com/CyberShadow/RABCDAsm (I'm not sure CrossBridge or AdobeAIR SDK provides an integrated alternative)

vpmedia commented 10 years ago

Also please check out this commit: https://github.com/crossbridge-community/crossbridge/commit/294c54fb988dcdc9ca6cae1625f48ff1dff53a95 which added a new parameter for building SWCs using threads..

w-vi commented 10 years ago

Are you using the exports.txt ? Stripping unnecessary symbols saves a lot of space and speed especially if you include Flash++.h, because that's basically whole Flash API

JoeDupuis commented 10 years ago

I am not using exports.txt, because I was under the impression that it needed to be in -O4 or that debug symbol would be stripped mode, but it seems like I maybe wrong.

I will try it.

In the mean time, I found that MXMLC takes forever to build (20 minutes, still building) if I use the Flex's mxmlc (which rely on the old asc compiler to compile), but only a minute if I use the Air's mxmlc (which use asc2 instead). So at least, am able to produced my debug SWF from my crossbridge SWC now.

Though am still not able to use GDB, I have opened another issue about that #55

I will try a exports.txt build soon.

JoeDupuis commented 10 years ago

Also at the moment, I build my C++ app into a SWC and link it through mxmlc with my other swc, but I want to be able to link my other swc files with my c++ app through g++. Which should minimize the number of step, speed up the compilation and ease up the workflow to produce a debuggable swf.

GCC can't link with swc now, I'll check if there is a work aound (maybe with a SWF extractor like proposed in this thread).

JoeDupuis commented 10 years ago

Little update, if I merge the AIR sdk with the Flex sdk (replacing the mxmlc and compc of flex by those of air) as shown here: http://helpx.adobe.com/x-productkb/multi/how-overlay-air-sdk-flex-sdk.html allow Intellij to build the app.

The normal mxmlc started from a console also finished after 36 minutes, so it is basically useless for development. No choice but to use the one that come from Air.

IDE that use Air sdk directly for compiler won't suffer from the issue, but those that can't and only use the Flex structure (like Intellij idea) have no choice but to merge the flex and air sdk to build the final SWF. I'll probably write a guide or something in the wiki when I'll have time.

I'll try with the exports.txt file now.