I just added code like this to the constructor:

if(!_class_initialized)
{
        Object.defineProperty(XML.prototype,"0",
                        {
                                "get": function():XML{return this as XML},
                                "set": function():void{},
                                enumerable: true,
                                configurable: true
                        }
        );
        _class_initialized = true;
}

where _class_initialized is a static boolean.

This sliced the memory requirements for XML instances in roughly half!

Not totally thrilled with the conditional code in the constructor, but I don’t 
have any better ideas at the moment.

Between the improvements I’ve made to XML and aggressive work on removing 
extraneous object references (particularly XML), I’ve reduced the memory 
footprint of my app for a particularly complex document from about 155MB down 
to 103MB.

The memory impact of using XML went from about 75MB down to 22MB. (That’s for 
well over 100,000 nodes kept in memory.)

Not bad for a few days work… ;-)

Harbs

> On Dec 9, 2019, at 7:19 PM, Greg Dove <greg.d...@gmail.com> wrote:
> 
> btw I am still happy to look into the possibility of doing a first time
> 'get' access for the Class itself on its package that runs static code, but
> as Alex pointed out, it could have issues with the minified version, so it
> is more at 'investigate' rather than 'solution' stage. I have not
> prioritized this for now...
> 
> 
> On Tue, Dec 10, 2019 at 6:13 AM Greg Dove <greg.d...@gmail.com> wrote:
> 
>> This might be a good candidate for getting the static initialization code
>> block working (it is currently not in js).
>> 
>> We discussed that recently in another thread.
>> 
>> public class MyClass{
>> 
>> {//static init block
>> COMPILE::JS{
>>  Object.defineProperty(MyClass.prototype,"0",
>>        {
>>                "get": function(){return this},
>>                "set": function(){},
>>                enumerable: true,
>>                configurable: true
>>        }
>> );
>> }
>> }
>> 
>> public function  MyClass (){
>> 
>> }
>> 
>> }
>> 
>> On Tue, Dec 10, 2019 at 6:00 AM Alex Harui <aha...@adobe.com.invalid>
>> wrote:
>> 
>>> Did you try:
>>> 
>>> function get 0():XML { return this; }
>>> function set 0(value:XML) {}
>>> 
>>> Within a COMPILE::JS, I think the variables:
>>> 
>>>   this["constructor"]
>>>   this["__proto__"]
>>> 
>>> are available.
>>> 
>>> HTH,
>>> -Alex
>>> 
>>> On 12/9/19, 8:27 AM, "Harbs" <harbs.li...@gmail.com> wrote:
>>> 
>>>    In my question to minimize memory requirements in XML, I’d like to
>>> optimize the zero index accessor.
>>> 
>>>    Right now, we have Object.defineProperty in the XML constructor. The
>>> byproduct of that is we have a function defined on every single instance of
>>> XML. Ideally that should be on the prototype object. This should
>>> drastically reduce the memory requirements for instantiating XML.
>>> 
>>>    In JS, that’s pretty easy to do:
>>> 
>>>    Object.defineProperty(thePrototype,"0",
>>>        {
>>>                "get": function(){return this},
>>>                "set": function(){},
>>>                enumerable: true,
>>>                configurable: true
>>>        }
>>>    );
>>> 
>>>    I’m struggling with how to do it in AS3. How can we get a reference
>>> to the prototype outside the constructor or have the compiler construct
>>> this kind of function automatically?
>>> 
>>>    Thoughts?
>>>    Harbs
>>> 
>>> 

Reply via email to