Optimize UnresolvedAVM2Item.resolve for replaceAS3 of very large files - #266
Optimize UnresolvedAVM2Item.resolve for replaceAS3 of very large files#266NutchapolSal wants to merge 7 commits into
Conversation
…functions and memoization
|
Thank you for your contribution. I think there can be a problem in searchPrototypeChain. Other way could be to searchPrototypeChain to be not static, but that would require to put the correct AVM2SourceGenerator object to all its calls (?). This is also reason why I did not merge your previous PR. And for the ResolveAccelerator: I think it is okay to have it the same file. |
|
I think it'll be a while until I can get back to working on this. |
redo of #265 but merging into the correct branch this time
A game I'm modding has an extremely large MainTimeline AS3 file, compiling the file takes minutes each time. Using VisualVM sampler, I found places that needed optimizations and implemented them.
Changes:
AVM2SourceGenerator.searchPrototypeChainby memoizing the entire call toabc.findPropertyDottedChain.parseWithSuffixandaddWithSuffixto use a pre-compiled regexUnresolvedAVM2Item.resolveinto multiple private functions (helps in pin-pointing where performance problem is in VisualVM). they're namedresolve1toresolve10for nowresolvecallsUnresolvedAVM2Item.resolve1using a precomputed hash mapPropertyAVM2Item.resolveby refactoring parts of it into individual functions and memoizing name index lookup. (interestingly, just refactoring theloopobjTypefor loop into its own function with a custom return value class already cuts down the runtime by half without any other optimizations.)Results:
I've tested on two different SWFs and scripts
First one ActionScript3Parser.compile total time from 65.8s to 6.6s
Second ActionScript3Parser.compile total time from 268.2 to 19.4s
also a question, Is having an inner class like
UnresolvedAVM2Item.ResolveAcceleratorfine? or should it be in a separate file instead? note thatPropertyAVM2Itemalso has its ownResolveAccelerator