Hot Reload for AIR

I think it may be a great improvements in our developer’s life.
So I’m looking for the people who interested, has time and want to participate.

  1. Create command line process that looks for file changes in src directory, it’s a Socket Server as well
  2. Take these changes and send it to client application connected via Socket
  3. Replace changed classes and rerun the app

Any thoughts are welcome, let’s discuss it here.

I don’t think it is really essential

technically you already have it but maybe not the way you want it

ADL is your “hot reload”
see AIR Debug Launcher (ADL)

look at the bottom ADL exit and error codes
1 is for “Successful invocation of an already running AIR application. ADL exits immediately.”

that means you don’t need to close and then relaunch, you can just launch over and over again

the difference is you expect “hot reload” to work automatically
with “looks for file changes in src directory”

where it is more an “on demand” thing eg. run a command to reload the code when you need it

eg. as the page example show with ant

<property name="SDK_HOME" value="C:/AIRSDK"/> 
<property name="ADL" value="${SDK_HOME}/bin/adl.exe"/> 
<property name="APP_ROOT" value="c:/dev/MyApp/bin-debug"/> 
<property name="APP_DESCRIPTOR" value="${APP_ROOT}/myApp-app.xml"/> 
<target name="test"> 
    <exec executable="${ADL}"> 
        <arg value="${APP_DESCRIPTOR}"/> 
        <arg value="${APP_ROOT}"/> 

so it seems what you want is something like inotify or fswatch
see for ex Watch Filesystem in Real Time on OS X and Ubuntu

On Windows, just use WSL to monitor the src/ folder and run a script
(provided you’re on a recent Windows 10 with WSL 2),
but hmmm I think you will not want that all the time

I say that because the default in Flash Builder is to build automatically and that is the first thing I deactivate, personally I don’t want something that build automatically each time some amount of chars in the code change, but only when I decide I want to test it.

So to do that “hot reload”, you would just need a bash script that launch ADL and check for the exit code.

But really, you just need an automated build, a mix of bash script and ant can be enough.

The “Hot reload” thingy is really overrated, “oh look it’s magic I can see visual update in my app and I didn’t even have to click a button”, yeah whatever if you want, but what is Hot reload exactly in the details ?

  • you need to recompile that SWF that ADL is running
    that’s automating MXMLC on the command-line
  • then it’s launching ADL with that SWF and the app XML
    that’s automating ADL on the command-line

Side note:
if compiling the SWF is what is “too long” for you

You could use incremental compilation with MXMLC
You can use $ mxmlc -incremental=true

You could use the Flex compiler shell, eg fcsh
but you would need to use the Adobe or Apache Flex SDK
and it got its own set of problems
see Build: add option to compile with fcsh (Flex Compiler Shell), if available

And with the AIR SDK you could use ascsh
ActionScript Compiler 2.0 Shell (ascsh is to AIR SDK as fcsh is to Flex SDK)

But I would say, you’re really complicating your life for not much,
a good solid automation of MXMLC is usually enough.

You have all the tools already there, you just need to automate them the way you like.

It really depends how you test and debug your app, hot reload will not magically solve the day-to-day problems, on macOS for example sometimes just testing with ADL is not enough I do need to fully deploy the AIR app as a “real installed app”, on Windows I often need to test again the “real installed app” because I need to test into a specific Win7, Win8, Win10, etc.

And if you test on the hardware itself, eg. mobile device, then forget hot reload it will simply not work the way apps need to be signed, yeah even with side loading etc.

But a fully automated pipeline, that works everywhere.

1 Like

This is the typical argument you get from people who are used to code static code and what to stay in that old paradigm. Dynamic applications frameworks/methodologies exist since more than 30 years ago and if they were thought from the beginning we would not have such prejudgment from people who are stucked in the past thinking their way is the best. If you look at nature everything is dynamic only the programmer is sleeping in his cave thinking that the painting he drew on the cave wall cannot take life and be a movie. You typically see arguments like dynamic code is over rated.

This is again not true and that’s due to @zwetan lack of knowledge and wisdom.

Sometimes @VladimirCores/all others don’t believe what @zwetan is giving as an answer. Simply what ever he thinks is impossible is due to his lack of skills, knowledge, creativity, etc…

He is really opinionated and very narcissistic and he thinks that he’s knowledge is absolute truth.

Actually what is possible with the Flash Runtime and Flex/AIR framework is endless. What you are talking about is already possible.

There is already the possibility to load and unload SWF on the fly so your thought process might just need to adjust a little bit in the right direction. I am not saying that this is the best solution but here is what you can do.

  1. Instead of tracking the src folder you might want to track the respective SWF file of your module since it is possible load/unload them on the fly.

  2. You don’t need to use a server socket you can directly make the core of your app as a modular structure which is by himself tracking itself.

  3. Instead of thinking in terms of classes you should think in terms of Bundles(SWF) which are all independent parts of a bigger unit. This is how you can achieve modularity.

The whole AVM was built with the wisdom of modularity in mind so there is room for lot of creativity in what is possible.

1 Like

Let’s be clear about a couple things.

When you work within the ecosystem of Flash/AIR/Redtamarin/etc. whatever involving the AVM2 etc. you can not change the rules of your environment.

And so the basic rules are you take ActionScript sources as text and you compile that to bytecode and then you need a runtime (in general) to interpret and execute that bytecode.

The way that those runtimes are setup is that you “load” bytecode in a hierarchy of “environments” or Domain or ApplicationDomain, following this order: you first have the builtin, then the shell or playerglobal/airglobal, then you have the user code.

And important rule, you can not override or redefine something that has been already loaded before you.

The way those environments work is that once a definition is created, you can not override it or replace it, that’s why you can not replace a class like String with your own custom String class, anything loaded is like a constant and so immutable.

So in order to do that “Hot Reload”, to be able to reload whatever user code that have been edited/updated you DO HAVE TO reset that runtime state.

Under those rules you can not just replace bits of bytecode this and there “on the fly” in your still running runtime and expect it to work, it will simply not work.

Now what is really “Hot Reload” ? why do you need it ? for what purpose?

Usually, you’re programming an app editing sources code and you want to “see” as fast a possible the result of those changes in the “test app” currently running.

You will very unlikely be able to preserve the current state of your currently running app when you “reload”, so at best, even if you do not need to relaunch the app, it will still reset to a default state.

You could find workarounds but then you would have to fit all your code into a specific framework that manage the state of the app to triggers some “hey something been updated” for you and as such it will not work with any code.

Another workaround is to restart the app with some parameters that “navigate” to some particular screen/page/state of the app, things you would use when you debug but then remove for prod.

Anyway, live editing within the app by default is not possible with AIR, you could use some tools that allows some properties to be live edited (like monsterdebugger, swfwire, whatever) but then those live edits would not be reflected in your source code.

By the way a lot of people abuse the terms “live coding”, " real time", etc. and they make even such claims as it will not restart or reload the code while in fact it has no other way to reload the code because it is how the runtime works, there is no other way, at best they do a “fast” reload but my point is they still reload the bytecode.

And how fast is somewhat subjective, I would argue that a better CPU and more RAM beat any incremental compilation trickery.

So @r0cketleague , I’ll say it once: you can perfectly disagree with anyone, people have different opinions etc. but when you come to make things personal like telling someone his “lack of knowledge and wisdom” this is simply not acceptable.

Please keep the argumentation about the technical subject at hand, and if you do make anymore personal attacks on anyone your account will be simply and purely deleted.

I never ever do what you mention above, but let be clear: this forum is not a free ticket to come and spread personal attacks whatever your reasons.

We are talking about tech stuff, we do not talk about politics, the character of people, the whatever is considered personal.

Who or what give you the almighty right to judge the knowledge of someone and as such not even providing the technical justification to prove the opposite point when you disagree ?

There 1000 and 1 way to do things on the technical side, this can be argued, people and in general developers can have opinion about it, even strong opinion about it, but that’s it.

NOTHING give you rights to attack the personal character of people here, period.

And more importantly you don’t need to, repeating those stuff does not bring any more credentials to whatever you say, you’re like a gorilla beating his chest and yelling “you’re stupid, I’m right”, not gonna help to prove your point.

So those things you said related to me are completely uncalled for,
those are personal attacks and not related at all to the subject of the post.

And you have been warned just before.

You claim a lot of stuff, so feel free to prove me wrong by posting your “proof” wherever you want, but “as is” I’ll kick your ass out of this forum because you keep doing personal attacks.

Just to prove my point, look at ApplicationDomain

All code in a SWF file is defined to exist in an application domain. The current application domain is where your main application runs. The system domain contains all application domains, including the current domain, which means that it contains all Flash Player classes.

Every application domain, except the system domain, has an associated parent domain. The parent domain of your main application’s application domain is the system domain. Loaded classes are defined only when their parent doesn’t already define them. You cannot override a loaded class definition with a newer definition.

I could take the time to educate you, even showing you exactly the C++ parts in the avmplus sources to prove it even more, but sorry, not sorry, I do not waste my time on trolls who comes to a forum only to prove their endowment is bigger than anyone else.


@zwetan thank you very much for explanation of things inside AIR ecosystem, even if I’m aware of how it works [UPDATE, after reading removed comments] (but maybe not, not about all).

Let me break this into parts:

  1. Now what is really “Hot Reload”
    I think about what is “Hot Reload” in example from Flutter, where on save all changes propagated to the run-time (state preserved within Flutter framework).
  2. Why do you need it?
    I want to minimize waiting time of VM to restart by simply avoid it. I don’t really care about state preservation for now.
  3. For what purpose?
    Even in Web “Hot-Reload”, like we see with Vue CLI (backed by Webpack), become a development standard. And because I still believe AIR / AS3 is great platform I want to have similar feature here.

Maybe we could ask Harman team to implement something that will allow us to replace code running on specific domain in runtime (nor in airglobal or other system libraries)?

@r0cketleague loading and unloading parts of SWF / SWC looks like a good idea, but if I load the same class again in the same ApplicationDomain, will it override the old one? (never tried it)

OK, so did you measure how long it takes now?
how long do you wait exactly?

how do you build and test currently?
how do you compile the SWF? have you already used incremental compilation?
do you recompile only the as3 sources or also the assets? the ANE? etc.

do you do it on the command-line ?
do you use ant? make? bash?

do you do it from an IDE?
so what IDE are you using?

how long it takes from “making an update to the code” to “seeing the changed results on the screen” ?

when you have this measurement, then tell us how you imagine “Hot Reload” will be faster?

My point is you have an ideal idea of how “Hot Reload” should work but you don’t really have hard numbers to back it up, what is “slow” ?, what is “fast” ?

without measures you can not know that, so the “I need Hot Reload as a development standard” point becomes kind of moot

It is like about performance, saying “I want AIR to be faster” is nice and all, but if you don’t measure it first you’re wasting your time.

yeah it’s not like they already have 200+ issues to go through

Before asking Harman to do something, maybe you could try and show what you tested?
where is your automated build script?
what would you expect to be different? at at which level?

“I want things faster” does not cut it

  • you have to show the current numbers, eg. it takes that long to compile code and that long to show in the ADL to test it
  • you have to show what you already tried to make it faster
  • and then you have to tell how much gain you would expect from the “hot reload” feature

the “slowness” you are apparently experiencing could be caused by many other different things than not having “Hot Reload”

maybe it is a problem with the compilers options
maybe it is a problem with the Java setup to use more memory to compile faster
maybe it is a problem with the Java version installed on your OS
maybe it is a problem with the hardware, eg. old machine, weak CPU, not enough RAM etc.
maybe it is a problem with the sources being on a SMB remote network drive
maybe it is a problem with the OS being 32-bit

maybe it is a problem with your expectation of “speed”
for ex: redtamarin on the command-line, the debug runtime takes 300ms to startup,
the release runtime takes 30ms to startup

it is the same logic with ADL, it will expect a debug SWF and will run in debug mode, and because of that you should expect a 500ms startup time, and certainly not a 50ms startup.

well @r0cketleague been kicked so he not gonna be able to answer.

When you load a SWF there is a difference between code and assets
things like sound, image, etc. can loaded/unloaded and reloaded (there are limitations on iOS see the archive)
but for code, it is what I mentioned earlier, you can not reload the same code definition

it is very easy to test by yourself, declare a class like test.foobar.MyClass
compile it once to mytest1.swf and a second time to mytest2.swf
maybe just changes some property string to different strings

load first mytest1.swf in the current ApplicationDomain
then load mytest2.swf in the same current ApplicationDomain
then see the error you get

but if I load the same class again in the same ApplicationDomain, will it override the old one?

answer is no, it will not override the class definition, you will get an errror

never tried it

you should