I'm Ross, a frontend engineer at Flickr.http://www.flickr.com/photos/protohiro/5123921842/
This is a story about problems we found after the launch of that photo page, and a few of the unanticipated consequences of building a page from scratch using YUI3 and the Y! Performance GuidelinesThe primary goal of the project, from the engineering side, was to improve performance:The old page took 4-6 seconds to loadThe frontend code was 5 years old To put some perspective on it, the JS contained hand-coded special cases for Opera 7 There were tons of global variables, and a dependency tree that was so complicated that we were terrified to pull out pieces of JS It was ready to be put to rest.
We investigated doing a retrofit with YUI3 We determined that it would take longer to do that than it would to throw everything out and start from scratch We also determined that retrofitting wouldn't really improve performance:The only way we could meet our goal was to throw everything awayWe started from scratch using YUI3 and the Y! Performance GuidelinesAnd I mean, really started from scratch. We used empty CSS and JS files and built the page againhttp://www.flickr.com/photos/jasonscottmeans/3391919037/
Page load times are down significantly (900ms for Safari, 1.5 for Chrome) We essentially cut the load time in half for the worst case (IE), and reduced it by 80% for the best case (Safari)Code is modular and maintainable The architecture will last us for the next 5 years, even if the individual modules that make it up don't Modules and dependencies mean that 5 engineers can work on the page at the same timeDevelopment time was extremely fast Existing gallery modules mean you don’t have to reinvent the wheel Convenience methods mean you can do extremely complex things with very little code (more on this later) Good documentation means that even though we weren't initially familiar with YUI3's syntax, we soon picked it up Porting code from YUI2 to 3 is an easy process – analogous functions exist, and it's a simple matter of changing the syntaxhttp://www.flickr.com/photos/kevinkyen/4721020630/
99% of the things we used YUI3 for went off without a hitchBut there were a few things that caught us by surprise Some where caused by using YUI3, and some were caused by implementing the Performance Guidelines The guidelines are taken as gospel at this point; everyone know them and tried to implement them We found that, at the edges of normal use, some of the guidelines start to break downI'm going to spend the rest of this talk going over the 4 problems that we found, and how we fixed each one.These all happened after launch, and most of them were reported by usershttp://www.flickr.com/photos/warquel/3991665628/
With this approach, you are essentially swapping out one JS lib for another, with the fewest number of code changes possible. You don't get a lot of the architectural improvements, but you still get deferred loading and the performance improvements internal to YUI3 itself.This is definitely the fastest way to convert over to YUI3. We found that you could convert most reasonably sized JS files in a day or less. You can even continue to use YUI2 widgets, with 2to3.http://www.flickr.com/photos/bflv/4032221304/
This obviously takes a lot longer, but will result in terser, more easily maintainable code. You separate code into discrete modules, set up dependencies, set up a combo-handler, and load only the JS you need on each page.
We used both techniques; the older, more stand-alone or one-off features we simply converted enough to work, tossed them into a module, and then left them alone. The more central and often used parts we entirely re-wrote (these were also the modules that we expected to use on other pages).The combination means we were able to go entirely to YUI3 on the photo page in 6 months, with 5 frontends working fulltime.
It’s easy to say that it would be too much work to convert your site over to YUI3. Instead, give it a try. Convert a small part of your site to use YUI3 as a test, and see how long it takes with your setup. Use that as ammunition (along with all of the studies that show how small performance improvements lead to much higher levels of conversion) to get time and resources to convert everything over.We used the photo page as a launching pad, since it’s the biggest and more important page of the site. Now we are converting over all of the other pages as we get to them. The entire process will probably make more than a year.
Converting over to YUI3 gives you a speed boost right off the bat, but there are things you can do to make it even better.These are some things that worked for us
This makes sense in most cases, since script tags block and slow down the page from being rendered.But if your page depends heavily on JS, it can actually increase perceived loading timehttp://www.flickr.com/photos/sshb/3981130921/
It means that the bulk of your JS won't be downloaded and executed until a second or two after the rest of the UI. Having no-JS fallbacks also makes it worse.Instead of a button that does nothing for a short time, it actually takes you off the page.The problem is exasperated by using YUI3's deferred module loading .http://www.flickr.com/photos/blueskin808/1422588776/
We include a small amount of JS in the head, enough to attach click events and to show a busy indicator.We then start to queue up clicks.When a module registers itself, it checks the queue and performs the necessary actions.The action queue code handles cleanup of the busy indicators. http://www.flickr.com/photos/boliston/3958674786/
It tricks people into thinking the UI is responsive.Action queuing doesn't actually solve the problem, it just improves the perceived load timehttp://www.flickr.com/photos/markscott/1117392453/
Page load times are down significantly (900ms for Safari, 1.5 for Chrome)Code is modular and maintainableThe architecture will last us for the next 5 years, even if the individual modules that make it up don't
These users get pages that sort of work, but don't have all the JS modulesIt's their problem to fix, but most can't do anything about itWe had to fix it on our endhttp://www.flickr.com/photos/simonhua/4696240744/
We replaced the names of modules with single or double character strings. This algorithm wasn't reversible, but it was easy to implement and doesn't require a database to store shortened names.We have to run the script that builds the substitution dictionary every once in a while, but that's easy
They are a small minority at the moment, but eventually we'll have to deal with this problem.1600 characters or lower is the limit we found covers pretty much everyone.http://www.flickr.com/photos/inkiboo/203350186/
It seems that some corporate firewall refuse to load any URL that has the string 'xxx' in it. We had to implement a check that would use the longer version of the string if xxx was detected. There is a long list of words that triggers this response from corporate firewalls. http://www.flickr.com/photos/sahlgoode/5012048467/
Not just scrolling, but almost all UI interactions requiring a click or a draghttp://www.flickr.com/photos/lin/372711782/
Both of these need to poll, with setInterval() in case the elements don't exist yet. We found that we were able to create our own delegate method, using Y.on and Y.Node.test that was twice as fast, when run through a massive selenium test. This isn't to say that ours is better (it isn't), but that Y.delegate() has to handle a lot of cases, and has baggage for most uses cases.
This probably goes without saying, but customizing the solutions for each situation is obviously going to be faster.What was surprising to me was just how slow delegate and on were before we customized them.http://www.flickr.com/photos/cybertoad/2102752062/
Don't assume that, just because you're using an established library, you don't need to know what's going on under the hood. We removed all instances of Y.delegate and Y.on, and massively improved the click performance of IE. YMMV.http://www.flickr.com/photos/roadsidepictures/1389358202/
There are things on every page that are only used very infrequently. We found that most of the buttons on our photo page are used a very small percentage of the time, and that most users are just there to passively view the photo
There is no need to include markup, JS and CSS on the page at load time for things that are rarely used. Instead, attach event handlers that will fetch the markup and invoke Y.use() to fetch the CSS and JS.
It’s definitely not a good an experience to have to load things only when, for example, a button is clicked. You can make it seems faster by showing a loading indicator when the fragment is being fetched, or have the markup fetch start early, when the user mouses over a link (lots of false positives from this, though).One optimization is to fetch multiple fragments at once, as soon as it becomes clear that the user will need them at some point.
DOMReady and window.load are meaningless once you start deferring assets. They are no longer important moments in the loading of your page.http://www.flickr.com/photos/mattimattila/3822631755/
The important moments for us are:When the photo is visible, andWhen the JS is done loading and the UI is fully functionalTrack everything, but only actively monitor a few important metricshttp://www.flickr.com/photos/whiteoakart/471538245/
We generally take timing data from 1% of all users (on some pages, this is as high as 2-4%).This gives us enough data to create smooth graphs, without burdening too many page loads with the extra code needed to gather and report the timings.The exact percentage you need varies according to traffic.http://www.flickr.com/photos/wwarby/3016567069/
Having a visible dashboard that's easy to get to is a really important part of the feedback cycle. Engineers will notice when performance gets worse, and will investigate what caused it. They will also try to improve the load times and Also serves as quality assurance, since it lets you know when site performance is down.Side note: RRDtool is really useful for storing and displaying this kind of timing data.RRDtool is a round robin database that stores data at decreasing granularity as time goes on: http://www.mrtg.org/rrdtool/
Performance is excellent for Safari, Chrome and Firefox. IE8 is mediocre and IE7 is terrible. If we were to average all of these numbers together, it would mask the 900ms page load times we're getting with Safari.Lumping them in together also hides browser-specific problems. After a recent deploy, we noticed that the IE8 load times were slightly higher than normal; having separate graphs allowed us to find and fix the problem.The real solution is to have reference systems: a fixed computer, OS, connection, and browser configuration, that we can use to compare the performance of the page over time.http://www.flickr.com/photos/richoz/3791167457/
The real solution is to have reference systems: a fixed computer, OS, connection, and browser configuration, that we can use to compare the performance of the page over time.Put it under a desk or on a rack and have it hit a page every 10 or 20 seconds. You will get variation from things like load, but it should be relatively consistent.For bonus points, have your graphs show when deploys happened, and what changed for each.http://www.flickr.com/photos/br1dotcom/4737073824/
YUI3 is amazingIf you can't have real performance, fake itDig deeply into the JS library you useMeasure the moments important to youNEVER include XXX in a URLhttp://www.flickr.com/photos/cdhc/274211112/
YUI3 is amazingIf you can't have real performance, fake itDig deeply into the JS library you useMeasure the moments important to youNEVER include XXX in a URLhttp://www.flickr.com/photos/ennor/353250218/
YUI3 is amazingIf you can't have real performance, fake itDig deeply into the JS library you useMeasure the moments important to youNEVER include XXX in a URLhttp://www.flickr.com/photos/candyflossblackmarket/1139767634/
YUI3 is amazingIf you can't have real performance, fake itDig deeply into the JS library you useMeasure the moments important to youNEVER include XXX in a URLhttp://www.flickr.com/photos/jensaar/386863409/
YUI3 is amazingIf you can't have real performance, fake itDig deeply into the JS library you useMeasure the moments important to youNEVER include XXX in a URLhttp://www.flickr.com/photos/sterlic/4299631538/
YUI3 is amazingIf you can't have real performance, fake itDig deeply into the JS library you useMeasure the moments important to youNEVER include XXX in a URLhttp://www.flickr.com/photos/bobcatrock/2653120251/
Porting Flickr to YUI3 - F2E Summit
Porting Flickr to YUI 3Ross Harmes<br />
Porting Flickr to YUI 3Lessons in Performance<br />Ross Harmes<br />
Turns out that a small but vocal minority of users sit behind firewalls that restrict URL length<br />
This fixes the problem for almost all users… but Sonicwall turns out to have a limit below 1600 characters<br />