3 ms·
I went to a meet up a few weeks ago on Sencha Touch and how they did the Fastbook (http://www.sencha.com/blog/the-making-of-fastbook-an-html5-love-story/ http:/
by emehrkay 14y ago
I went to a meet up a few weeks ago on Sencha Touch and how they did the Fastbook (http://www.sencha.com/blog/the-making-of-fastbook-an-html5-love-story/ http://www.sencha.com/blog/the-making-of-fastbook-an-html5-l...) project to prove that HTML5 is, indeed, ready to provide host an application as complex as Facebook a few weeks ago and it opened my eyes in a few ways.
This article is correct, and provides an example, in saying that the DOM can easily create thousands of elements in milliseconds. However, the problem is that events and interactions with it all happen on a single process. Things load and block the thread, an event happens and blocks the thread, etc.
The Sencha guys did something really smart. They used an object pool with one object: requestAnimationFrame, as the core of their mobile platform and sent EVERYTHING to it. That way events, loading, or whatever, didn't block, but happened in a FIFO manor. They also kept the number of dom elements static and just reused them when needed, so an object pool of dom nodes -- no creating or destroying nodes.
The things that make working with the dom slow isn't only creating nodes, but applying styles, listeners, and destroying them -- basically creating an application.
I do agree with the overall premise that a lot of developers do not know the best methods/practices/patterns to utilize when creating complex applications. I learn new things daily and I hope that our community continues to teach itself and provide tools to make getting things done easier.
- Xion 14y agoHonestly, that doesn't sound like a best practice and more like a convoluted performance hack. It's one thing to use a pre-allocated memory pool for speeding up the creation of objects in native language like C++. Having to the equivalent while working several software layers above that is an example of extremely leaky abstraction. DOM and Javascript engines still need few more man-centuries of iteration to bring their performance closer to e.g. JVM which doesn't really require hacks like that anymore.
- ZoFreX 14y ago> e.g. JVM which doesn't really require hacks like that anymore. Is this the case? I used to be pretty in-touch with Java, but haven't been keeping up from the release of 7 onwards. I've picked it up again for game development, and 100% of the performance advice I've found is to use object pooling... but nearly all of that advice is years old, and I have no idea if it still holds true for JRE7 or even JRE6. It did strike me as something the JVM should be doing for me, so if that has been fixed, that news will be greatly welcomed by the Java game dev community.
- craigching 14y agoFor Java 6 and 7 I would say don't do object pooling, this is probably true for 4 and 5 as well. Creating a new object in Java is very inexpensive and it keeps getting improved. The only argument you might be able to make against creating lots of objects is garbage collection, and for that I'd say profile when you have problems and change only then.
- lucian1900 14y agoEspecially the newer generational GCs are very good at letting you create and destroy lots of short-lived objects. Object pools may only be useful for long-lived objects, maybe.
- pmahoney 14y ago"Public service announcement: Object pooling is now a serious performance loss for all but the most heavyweight of objects, and even then it is tricky to get right without introducing concurrency bottlenecks." -- Brian Goetz in 2005 http://www.ibm.com/developerworks/java/library/j-jtp09275/index.html http://www.ibm.com/developerworks/java/library/j-jtp09275/in... This article was also written when Java 6 was starting to get escape analysis, which can result in stack allocations in some cases. I recall taking a course in 2008 or so (Java 6). We were doing a genetic simulation of sorts, and the professor recommended using an object pool to speed things up. I implemented one and observed no measurable difference in my code's performance (these were very small objects used over and over again evolving new organisms). I hooked up a profiler and used that to guide me to some areas that could be improved, and a valuable lesson was learned.
- emehrkay 14y agoDoes everything that happens in the JVM happen on a single tread? I think that is the biggest bottleneck when you see slow performing web apps. I think that moving things off to web workers is the natural progression, but browser support...
- jfim 14y agoYou're supposed to do all your graphics-related stuff in a single thread. Swing and JavaFX aren't thread-safe.
- craigching 14y agoNot everything, just UI work for AWT/Swing. Pretty much every UI framework that I've worked with over my 20 years of experience is single-threaded, uses an event-based queueing architecture. I'm sure others have a different experience though ;)
- camus 14y agowell i would argue not everybody has a top of the line handset , and trust me html5 vs native makes a huge difference on cheap devices. You dont have to use all these tricks when you use IOS or Android widgets. And usually developping with Xcode or Eclipse IDEs makes the work far more easier than using any JS ide. Instead of using Javascript for the UI i usually use it to implement bits of business logic , algorithms i can easily port from plateform to plateform , so i get native UI and portable JS libraries.
- emehrkay 14y ago> You dont have to use all these tricks when you use IOS or Android widgets. I havent gotten too deep in native development on either platform, but don't they prioritize tasks automatically? JS doesn't, using requestAnimationFrame and web workers is doing exactly that. Wasn't the main knock against Android's UI lag because everything happens once allowing blocking and it was addressed with project Butter?
- mwcampbell 14y agoHave you successfully developed any iOS apps using the approach you describe (native UI, JS back-end)? If so, how did you embed a JS engine in your app and bridge between that and ObjC?