Sunday, October 12, 2008
Faster JSON Decoder - NOT :-(
I'm looking for a fast JSON decoder in AS3, and I'm really hoping that the next Flash player will have native JSON functions like IE8. The as3 core library has a decoder. Tested it on a one megabyte JSON String and it took almost 4 seconds to decode on my MacBook Pro. Wow ! There has to be a better way. Couple of former life ago, was really into lex/yacc and flex/bison. BTW - I laughed so hard when I read the name of the first link when I googled 'lex yacc' - The generated "C" code was very fast. So one of the "modern" way to write a lexical analyzer/parser is to use ANTLR. ANTLR has an option to target ActionScript. I Found a JSON grammar reference and made simple adjustments for AS3. Ran the ANTLR Tool on the 'g' files and compiled the generated AS files into a test harness. BTW - Had to adjust by hand the generated AS3 code, as it did not compile out-of-the-box :-( I passed a set of test cases for the exception of escaped string content. Now, back to the one megabyte JSON String. It took almost 29 seconds !!!! Wow ! Thinking about it some more. It kinda make sense, as I'm evaluating the string from a generated AST. Anyway, I believe you should "publish" your successes and failures. Like usual, here is the source code.
Subscribe to:
Post Comments (Atom)
3 comments:
How does your 1 megabyte JSON string fare if you eval it using ExternalInterface? I know there's a fairly hefty communication overhead, but is it fast enough to move a 1Mb object from Flash to javascript and back again in less than 4 seconds?
Actually - you must had read my mind - that is my next post :-) Yes, using external interface eval is fast - BUT...it is browser dependent :-( Safari was very good, IE sucked. In addition, I have tried other solutions that I will be talking about in my upcoming post. Stay tuned.
I am drawing some shapes on map. And i need to show shapes in the visible area of Map. I have tried different methods, from some maps the shapes are not completely coming to visible area of map. I have tried following:
var extent:Extent = GraphicUtil.getGraphicsExtent(this.graphics);
var yDiff:Number = 0;
if(this.shapeType == 1 || this.shapeType == 2){
yDiff = (extent.ymax - extent.ymin)/8;
}else {
yDiff = (extent.ymax - extent.ymin)/4;
}
this.map.extent.update(extent.xmin-yDiff,extent.ymin-yDiff, extent.xmax+yDiff, extent.ymax+yDiff);
this.map.zoomOut();
But still the shape doesn't come to viewable area. Any ideas u can suggest plz?
Post a Comment