Pure AS3, Flex Framework Dependencies, Filesize

10 views
Skip to first unread message

dtyrell

unread,
Mar 25, 2009, 9:30:55 PM3/25/09
to Smartypants IOC
Hi Josh,

I read the first two posts on this list - they mention the idea of a
pure AS3 branch.

Personally, I think that would be awesome! There are plenty of Flash/
Flex devs, myself included, who use the Flex Compiler to build pure
AS3 projects - often using Flex Builder, FDT, FlashDevelop or
TextMate. SWC files can be used easily by most, if not all, of them.
Even the Flash IDE can make use of SWCs as far as I know.

Flex is great, but sometimes the filesize overhead and rendering
performance is not acceptable for a particular application (a game
perhaps). Also, it's nice not to bind yourself to a particular GUI
framework. I'm building a Flex application at the moment which I plan
to migrate to OpenPyro (an AS3 Open Source GUI framework) after a
release or two.

I don't think it should be a branch though, or use conditional
compilation, or be split into 2 libraries.

If possible, and I'm not sure how easy it would be at this point, the
framework should be designed not to pull in any Flex classes (from the
mx namespace) unless a Flex related method or Class is referenced by
the application itself. Classes that are imported but not directly
referenced do not get compiled by default. So, if one doesn't use Live
Bindings or any other Flex specific features, the corresponding
SmartyPants Classes should not get compiled into the final application
SWF.

The great thing about the Flash Player is that one can do quite a lot
with a very small amount of bytecode. Some people can get quite
obsessed with SWF filesize - I get very sad if my applications go over
300KB:

Under 64 KB: Stoked
64 - 200 KB: Happy
200 - 300 KB: Mildly Agitated
300 - 500 KB: Extremely Sad
Over 500 KB: Violently Ill

Currently, referencing SmartyPants in a pure AS3 project adds about
276 KB to a Debug SWF (or 168 KB to a Release SWF). I must assume this
is because it is pulling a fair chunk of the Flex framework along with
it - I don't have a nice tool for OS X to examine exactly which ones.

I imagine that it might be quite a challenge at this point, but I
think that many Flash devs would love to be able to use SmartyPants to
handle DI for their applications. At it's core, SmartyPants would then
really just be an awesome AS3 Dependency Injection framework, and the
Flex specific features would exist along-side purely to assist Flex
development.

What are your thoughts on this? Would it be a huge re-design to
isolate the Flex touch-points and move them into their own classes (I
know it's not that simple!)?

Cheers, and thanks again for your efforts, very much appreciated.

shaun

Josh McDonald

unread,
Mar 25, 2009, 9:40:13 PM3/25/09
to smartyp...@googlegroups.com
Hi Shaun,

I can think of some small changes that should cut down the amount of Flex code "butterflied-in" to almost nothing, but I can't get it to a state where it will compile without the Flex .swcs unless I re-implement ChangeWatcher, as there's no way the compiler can know whether or not your application uses live rules without building two separate rules DSLs, and even then I'm not sure it would be possible. So to get completely Flex-free, we'd have to either reimplement (or copy, I'd have to check the license) ChangeWatcher, or have a compile-time switch that leaves out support for live rules.

However, I'll make the small changes this evening and run a few tests and see if it makes much of a difference.

-Josh

2009/3/26 dtyrell <Dar...@gmail.com>



--
"Therefore, send not to know For whom the bell tolls. It tolls for thee."

Josh 'G-Funk' McDonald
  -  jo...@joshmcdonald.info
  -  http://twitter.com/sophistifunk
  -  http://flex.joshmcdonald.info/

dtyrell

unread,
Mar 26, 2009, 7:00:33 AM3/26/09
to Smartypants IOC
Hi Josh,

That's great news!

I did a little test with the SmartyPants SVN source: by removing all
references to SPLoggingUtil my compiled SWF dropped to 20KB / 16KB
(for a Release build)! I still had to drop the flex.swc and
framework.swc files into my project lib folder to compile due to the
ChangeWatcher as you mentioned.

The only files I had to touch were:
InjectorImpl
and LiveInjectionManager

Best of luck with the "small changes" :)

Cheers,
Shaun

On Mar 26, 3:40 am, Josh McDonald <j...@joshmcdonald.info> wrote:
> Hi Shaun,
>
> I can think of some small changes that should cut down the amount of Flex
> code "butterflied-in" to almost nothing, but I can't get it to a state where
> it will compile without the Flex .swcs unless I re-implement ChangeWatcher,
> as there's no way the compiler can know whether or not your application uses
> live rules without building two separate rules DSLs, and even then I'm not
> sure it would be possible. So to get completely Flex-free, we'd have to
> either reimplement (or copy, I'd have to check the license) ChangeWatcher,
> or have a compile-time switch that leaves out support for live rules.
>
> However, I'll make the small changes this evening and run a few tests and
> see if it makes much of a difference.
>
> -Josh
>
> 2009/3/26 dtyrell <Dars...@gmail.com>
>   -  j...@joshmcdonald.info

Josh McDonald

unread,
Mar 26, 2009, 6:47:45 PM3/26/09
to smartyp...@googlegroups.com
The Logging util did it? That's weird. I was thinking about something else... I'll see what I can sort out there.

2009/3/26 dtyrell <Dar...@gmail.com>
  -  jo...@joshmcdonald.info

dtyrell

unread,
Mar 26, 2009, 9:40:39 PM3/26/09
to Smartypants IOC
Yeh, must be those mx.logging classes referenced by SPLoggingUtil.

On Mar 27, 12:47 am, Josh McDonald <j...@joshmcdonald.info> wrote:
> The Logging util did it? That's weird. I was thinking about something
> else... I'll see what I can sort out there.
>
> 2009/3/26 dtyrell <Dars...@gmail.com>

Animesh Jain

unread,
Mar 27, 2009, 3:38:22 AM3/27/09
to smartyp...@googlegroups.com
Pretty cool! I never realized SmartyPants could add ~160kb to the size of an app. So this means with the newer release it should go down to 20 odd kb?

Animesh

Josh McDonald

unread,
Mar 27, 2009, 4:41:04 AM3/27/09
to smartyp...@googlegroups.com
When I started optimizing it this afternoon, it was adding 36kb - the difference would be that I replaced a reference to UIComponent with a reference to DisplayObject  few days ago. It's now down to just under 16kb.

I've committed the updated sources, and there's a .swc checked in, but not up in the "download" link on the google-code homepage.

-Josh

2009/3/27 Animesh Jain <ani...@itasveer.com>
  -  jo...@joshmcdonald.info

dtyrell

unread,
Mar 27, 2009, 7:46:48 AM3/27/09
to Smartypants IOC
Awesome! I've updated my projects with the SVN SWC, and my plain AS3
projects are MUCH smaller now!

@Animesh: The older version wouldn't necessarily add 160kb to Flex
apps - that was just for AS3 apps where portions of the Flex framework
were being pulled in.

@Josh: Great work. Plain AS3 apps using the SWC will be much smaller
now. The only Flex dependencies remaining (if one were to include the
SP source instead of the SWC in an AS3 project) are:

impl.live.SourceEntry (due to mx.binding.utils.ChangeWatcher)
utils.Reflection (due to mx.utils.DescribeTypeCacheRecord)
utils.SimpleTraceLogger (due to mx.logging.ILogger and LogEventLevel)

But those might be impossible to work around - besides, using the SWC
is perfectly fine, so probably wouldn't be worth the effort anyway.

Many thanks,
Cheers,
shaun

On Mar 27, 10:41 am, Josh McDonald <j...@joshmcdonald.info> wrote:
> When I started optimizing it this afternoon, it was adding 36kb - the
> difference would be that I replaced a reference to UIComponent with a
> reference to DisplayObject  few days ago. It's now down to just under 16kb.
>
> I've committed the updated sources, and there's a .swc checked in, but not
> up in the "download" link on the google-code homepage.
>
> -Josh
>
> 2009/3/27 Animesh Jain <anim...@itasveer.com>
>
>
>
> > Pretty cool! I never realized SmartyPants could add ~160kb to the size of
> > an app. So this means with the newer release it should go down to 20 odd kb?
>
> > Animesh
>

Josh McDonald

unread,
Mar 27, 2009, 7:55:30 AM3/27/09
to smartyp...@googlegroups.com
Yeah, I've no real interest in removing reliance on the Flex .swc - but I don't want to be dragging in a bunch of framework classes I don't actually use and making life difficult for the AS3-only programmers :)

-Josh

2009/3/27 dtyrell <Dar...@gmail.com>
  -  jo...@joshmcdonald.info

dtyrell

unread,
Mar 27, 2009, 8:32:32 AM3/27/09
to Smartypants IOC
For sure. Anyhow, I'm stoked. Here are my figures for SP bytes added
to pure AS3 apps:

23,073 bytes (Debug Build)
15,970 bytes (Release Build)

On Mar 27, 1:55 pm, Josh McDonald <j...@joshmcdonald.info> wrote:
> Yeah, I've no real interest in removing reliance on the Flex .swc - but I
> don't want to be dragging in a bunch of framework classes I don't actually
> use and making life difficult for the AS3-only programmers :)
>
> -Josh
>
> 2009/3/27 dtyrell <Dars...@gmail.com>

Josh McDonald

unread,
Mar 27, 2009, 10:29:06 AM3/27/09
to smartyp...@googlegroups.com
Glad to hear it's working out! Rule deletion is done, but my
girlfriend's cable •sucks• so I can't check it in til tomorrow when
I go home to join the Adobe bug quash.

-Josh

Sent from my iPhone
Reply all
Reply to author
Forward
0 new messages