Skip to content

Please consider making reflection (Type and ByteCodeType) "smarter" about caching  #54

Open
@GoogleCodeExporter

Description

@GoogleCodeExporter
I love org.as3commons.reflect.*.  But, I do not love the way it manages type 
information.

It seems that type information is parsed and cached "en masse" -- that is, all 
type information for the entire .swf is loaded and then sits like a lump in 
memory.  Apparently, the only methods for managing the cached information are 
ByteCodeType.fromXxx() and ByteCodeTypeCache.clear().  (At least, it seems this 
how ByteCodeTypeCache works.)

I have very large project which uses ByteCodeType in many different places and 
at different times in the application life-cycle.  I call 
ByteCodeType.fromLoader() at startup to fill the cache with type information.  
Afterwards, ByteCodeTypeCache.clear() is not fine-grained enough to manage the 
cache -- performance would suffer if the type information was loaded and 
cleared en masse again and again as my application ran.  On the other hand, my 
application doesn't make use of *all* the type information for the entire .swf, 
so it is a great waste of memory for all the ByteCodeType-related objects (and 
strings!) for every possible type in my application to sit in memory.  It is 
also a great waste of time...  it takes several seconds for my application to 
start (while ByteCodeType.fromLoader() runs, loading the universe).

So, this issue to ask you to please consider the following:

1) Parsing type information more "on-demand", perhaps loading each type only 
when it is asked for (for example, when Type.forInstance() or 
ByteCodeType.forClass() is called).  Or, take it to the next level, and even 
parse individual member info on-demand (for example, when an instance of Method 
or Variable is needed).

2) Caching all type information using SoftReferences, so unused type 
information will naturally "fall out" of memory when no longer needed (i.e., 
let the application's actual set of references control what stays cached).

Ideally, an application should be able to freely use instances of Type and 
ByteCodeType and only pay the costs to parse, load, and store the type 
information that is actually used.

Perhaps calls such as ByteCodeType.fromLoader() should simply do some 
lightweight "cursory" parse (maybe just build a list of the type names and 
offsets to where the type information is), and leave the more detailed parsing 
until later (on-demand).

It would also be extremely desirable for any time-consuming functionality to 
operate asynchronously, providing an event or callback notification when the 
result is available.  (By "asynchronous", I meant dividing up the work and 
processing it in "slices", never taking longer than some caller-specified 
duration per slice.)

Original issue reported on code.google.com by [email protected] on 27 May 2011 at 10:03

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions