10 ms·
Twitter crashes itself with commas
- falcolas 14y agoI guess I'm most surprised (alarmed?) that there is 4 mb of Javascript that has to be executed on a Twitter page.
- evilduck 14y agoMaybe 4mb of memory required in the compilation step, the file mentioned in the article, "t1-more" is only 355kb over the wire.
- debacle 14y ago350kb of JS is still a ton of JS. I remember deploying YUI almost five years ago now, and 130kb was 'too much' JS.
- awj 14y agoThe main page for the site I work on makes extensive use of jquery, jquery ui, backbone, a crapton of custom javascript, and more of the OpenLayers library than most places I've seen. It weighs in at 330kb and has a decent bit of fat to trim. What on earth are the people at twitter doing that warrants that much code? Maybe their single page app -> dedicated page transition was more about disabling some things and rewiring urls with the plan of taking advantage of the dedicated setup later?
- notatoad 14y agomost of twitter is still on single page app. they announced the change back to dedicated pages, but only rolled it out to user pages so far, afaik.
- jlarocco 14y agoIt's been a long time since I looked at the Twitter API, but I remember some of their API responses being hilariously inefficient. I don't remember the specifics, but something like retrieving a user's tweets the JSON would include a user "object" with every tweet message. The response would be something like this: [{user: {name: 'jlarocco', userid: 1, /* 50 other attributes */}, message: 'my first tweet', id: 1, time: 123456}, {user: {name: 'jlarocco', userid: 1, /* 50 other attributes */}, message: 'my second tweet', id: 2, time: 123498}, /* similar thing 18 more times */] If the rest of their stuff is like that, a 4MB Javascript file doesn't surprise me at all.
- shock3naw 14y agoNow that Twitter is 'stable,' the API is being overhauled and they are moving away from being a single page application. You forget Twitter has been dealing with technical debt for years. The fact that Twitter still runs on Rails and serves as much traffic as it does is testament to what the engineers there have built.
- riffraff 14y agoI think recently they added some options to omit nested informations in apis. OTOH, duplicated data _is_ easier to handle and produce and probably on the wire efficiency wasn't a big concern in the original twitter app.
- vacri 14y agoIt reminds me back in the day of the 'to html' converter in Microsoft Word. If you had a table in the original document, the converter would needlessly specify all the typeface information in each individual cell...
- falcolas 14y ago> that "bundle/t1-more" file is a whopping 4 129 653 characters. I'd have to imagine that 355kb is the compressed size, but that character count (assuming one byte characters, not UTF8) works out to be 3.938 megabytes. That's a lot of code. Even more when you consider it's been minified.
- slig 14y agoDoes anyone have the numbers of Gmail JS size?
- bgarbiak 14y agoAccording to Firebug: roughly 250 KB is transferred, half of that is lazy loaded (after DOMready, I suppose) and it looks like the biggest file (75KB) is from Google+. All scripts uncompressed (not un-minimized) weigh about 740 KB.
- falcolas 14y agoMakes me wonder if it's the difference between a different language being compiled to minified Javascript vs. minified Javascript.
- n-gauge 14y ago~790k (min) in IE8
- evilduck 14y agoWhy do we have to imagine and then speculate from there? This is trivial to inspect. It's 1.34mb on disk uncompressed but still minified. The copy Twitter is hosting right now is 1409121 characters minified but uncompressed. I have to assume the 4mb mentioned is output from some middle step (closure compiler output?) I'm not arguing the merits of that filesize, just that it's definitely not 4mb.
- unfasten 14y agoI ran into this problem last night and ended up looking at the script. File size is 4,129,653 bytes, on a single line. I had it saved to check out what the problem was, so here it is if you want to check it out yourself: https://dl.dropbox.com/u/24903613/hn/twitter-4MB-line.js https://dl.dropbox.com/u/24903613/hn/twitter-4MB-line.js Link to it on Twitter's servers (I uploaded to dropbox just in case the file expires or is changed): http://a0.twimg.com/c/phoenix/en/bundle/t1-more.5d72926b785051d84927ae194c9a7bfd.js http://a0.twimg.com/c/phoenix/en/bundle/t1-more.5d72926b7850...
- samarudge 14y agoFrom the comments > I believe it's Google Closure compiler putting commas in there. Someone else linked to an explanation of why > http://blog.vjeux.com/2011/javascript/javascript-comma-trick.html http://blog.vjeux.com/2011/javascript/javascript-comma-trick... </fact><opinion> So from the looks of it, the problem is in Opera's javascript implementation. I'm not sure how much Google uses Closure Compiler internally but I wouldn't have thought they would use code they knew to cause issues in some browsers. I guess that ether means the Opera implementation is wrong and the code should work fine, or Google didn't test this as fully as they should have done
- tseabrooks 14y agoIs it a bug though? Sounds like a conscious design limitation in the parser. A bad limitation, but not a bug. Sounds like it's behaving "as expected".
- icebraining 14y agoThey consider it a bug: We already knew that we had a limitation that other browsers don't have in the parser, and it was already considered important to fix. Breaking Twitter of course raises the profile of this bug.
- mistercow 14y agoECMAScript is a language with an ISO standard behind it. Any time a parser doesn't comply with that standard, it's a bug.
- gamache 14y agoThat "explanation of why", when you take the trouble of reading it, is just an explanation of how. The article ends with: Conclusion - Using the comma trick to do { }-less indentation is far from viable. However this may still be useful for debugging and overall it is fun to try new coding styles!
- seppo0010 14y agoReading the article and the comments made it more clear to me. Twitter is using some minification tool (maybe Google Closure) which attempts to reduce the number of characters used. Using commas you can reduce two characters by avoiding some brackets. if(true){dothis();dothat();} if(true)dothis(),dothat();
- tseabrooks 14y agoHeadline makes it sound like there is a bug with Twitter. In reality they are doing something totally legal, if a little gross to look at IMO (C / C++ embedded coder by training). The actual bug appears to be not a bug so much as a limitation in the Opera parser with regards to how many comma delineated calls it can handle at a single time. Somewhere around comma 1019 things get messy.
- deleted 14y ago[deleted]
- ajross 14y agoRight. "70's-style static limitation in Opera parser crashes Twitter" would be more like it. Seriously guys? You don't get to do dumb things just because you don't think syntax will be used....
- mibbitier 14y agoDo you think a js parser should also cope with a 10GB source file with nesting a million levels deep? I think it's pretty sane to suggest that a single statement won't be 4MB in length.
- ajross 14y agoIf I have a machine with many gigabytes of memory and ~100MB of stack space available (the latter requires some tuning at thread-creation time with current runtimes, but the former is frankly routine)? Yes. Yes, I'd expect my software to handle it correctly. The fact that you think otherwise is precisely the problem. If you don't want to write correct software (which, frankly, isn't any harder than writing broken parsers) you might want to reconsider your career choice.
- akkartik 14y agoEasy, tiger. Be nice. It's a plausible line of reasoning; getting personal interferes with the education process. You can't persuade if you alienate.
- gamache 14y agoFor the love of god, please someone tell me what is so offensive about the semicolon. When you replace a thousand of them with commas, nothing has been gained! When you start placing them only at the beginning of certain lines, subject to JS's parsing rules, you are thinking more, not less!
- tomjen3 14y agoIt shouldn't be necessary to write them in the first place. Anyway in this case I guess some automatic code reduction tool has decieded that four characters can be saved by changing it to commas. I doubt it was written that way to begin with.
- shaggyfrog 14y agoIt shouldn't be necessary for me to look both ways before I cross the one-way street in front of my home. But I do.
- georgemcbay 14y ago> It shouldn't be necessary to write them in the first place. I love Go's lack of semicolons but I don't extend that to some foolhardy attempt to write JavaScript without semicolons. In JavaScript, support for proper semicolon-less style is clearly lacking in practice if not in spec (if it weren't lacking this wouldn't be a oft-recurring story, but it is).
- Semiapies 14y agoThis parent comment really shouldn't be down-voted for saying the same thing half the people in this thread said an hour later.
- true_religion 14y agoThey didn't place the commas there by hand. What are you complaining about?
- mistercow 14y agoThis seems very likely not to be a programming style choice but some kind of optimization trick by a JS minifier/compiler. I don't think this has anything to do with the typical semicolon war.
- greghinch 14y agoCan someone please provide a valid, technical reason for not using semicolons other than "it doesn't say I hafta so I'm not gonna!" (that quoted bit should be read as if a 5 year old throwing a tantrum was saying it)
- tomjen3 14y agoYes, but I am not going to waste my time with it when you are not willing to debate it in good faith.
- pavel_lishin 14y agoI'm willing to, please don't withhold enlightenment to spite one guy.
- tomjen3 14y agoI write Javascript for a living, and the code standard requires semicolons. Anyway variables in javascript have function scope, so two variables with the same name in the same function always refer to the same value, even if declared twice. As a result I like to write all the variable statements at the top of each function, all in one var statement. The problem then becomes that you write var a, b, c, d; and then later want to add variable e. If you aren't careful you might accidentally write var a, b, c, d; e; if you do that, the program may still work but e now has global scope. This results in nearly impossible to find bugs that may only happen if the function is recursive or it is called (perhaps indirectly) by some other function with a similarily named variable. Considering that semicolons insertion mostly works, and the other can be a huge pain in the rear end, I can understand why people would want to skip the semicolons.
- tedunangst 14y agoIf you aren't careful, you might accidentally write var a, b, c, d, r;
- thedaniel 14y ago
- the_mitsuhiko 14y agoIt's very common for javascript compressors to reduce statements to expressions if that's possible. Even uglify-js does that and that ones is not particularly amazing.
- dherman 14y agoThis headline is misleading, especially given how much people love to argue about semicolon insertion. This has nothing to do with semicolon insertion. It's just about an artificial constant limit in how large a certain type of parse node (comma expression) can get in Opera's JavaScript parser. (Of course, Twitter should have tested in Opera!)
- Achshar 14y agoI remember reading about some twitter dev who apparently hated semicolons and went far and beyond to avoid putting semicolons. He was a bootstrap dev i IIRC. I tried googling but couldn't find anything again. maybe this is related?
- bgarbiak 14y agoYou probably mean this: http://news.ycombinator.com/item?id=3842713 http://news.ycombinator.com/item?id=3842713 But that's rather unrelated.
- mvzink 14y agoFurther context/information: http://news.ycombinator.com/item?id=3584635 http://news.ycombinator.com/item?id=3584635
- ericcholis 14y agoI found the lack of semicolons annoying when reading the Bootstrap jQuery plugins. Although, if I'm not mistaken, the exclusion of the semicolon is technically correct. So, both parties are at fault here.
- cpeterso 14y agoSomewhat off-topic, but: why semicolons? C, Pascal, and ALGOL (1958) use semicolons as a statement delimiter. Why was the semicolon chosen instead of, say, the period or newline? BCPL (like JS and Go) allows semicolons to be omitted if a statement ends unambiguously on one line. Was the semicolon a QWERTY home row key before or after ALGOL?
- chimeracoder 14y agoFor what it's worth, there's a precedence for it in formal, legal-style writing. UN resolutions, for example, are always written as a single sentence[1]. It makes sense when you think of an entire resolution (program) as a single goal (output/result), which involves many separate steps/clauses (statements) that need to be executed. A period is a terminator; it says 'This thought ends here', while a semicolon is a delimiter (ie, the clauses it separates are independent grammatically, but not contextually). [1]http://web.utk.edu/~modelun/resolutions.htm http://web.utk.edu/~modelun/resolutions.htm (Model UN rules, but you get the idea).
- mkopinsky 14y agoI have seen the same thing in mayoral declarations or the like. Whereas John Q. Doe is an upstanding citizen who has contributed to the city, and Whereas aforementioned Mr. Doe is an awesome dude, and Whereas some people who happened to contribute to my campaign are fans of Mr. Doe, Therefore, I, Mayor Wile E. Coyote do hereby declare Octember 31st, 2012 as John Q. Doe Day in the city of Acme, CO. In this context, the UN resolution is actually similar to the comma-style used here by Twitter. We don't want the statement/sentence to end, so we use semicolons/commas to make it continue, and end up breaking browsers/non-lawyer readers.
- jarek 14y ago> A period is a terminator; it says 'This thought ends here', while a semicolon is a delimiter Pascal takes this literally: semicolons separate statements, and a full stop ends the unit contained in a file ("end.").
- ars 14y ago
- saurik 14y agoThe title of this post was changed from "Lack of semicolons causes Twitter to crash in Opera" to "Twitter crashes itself with commas", long after it hit the front page (and in fact got all the way to #2); this sadly drops the (as far as I'm concerned) critical note that this bug only affects Opera, and makes it sound like this is Twitter's fault, when this is really Opera's fault. On the other side, this is why many of the comments, including the top comment, seem overly invested in the notion of semicolon insertion, as opposed to looking at the specific usage of replacing sequences of ExpressionStatements (even if separated by semicolons) with a single ExpressionStatement holding a very long compound Expression (separated by commas).
- ekoontz 14y agoNot sure if this is related, but starting yesterday, I've had to switch from Firefox to Chrome for twitter - Firefox uses all my RAM and beachballs.
- soulclap 14y agoI saw a couple of tweets today by Chrome users who were wondering where the 'new tweet' input form field went. So not sure if this problem is limited to Opera. (I am using Chrome as well and didn't have any problems but still.)
- madrona 14y agoCommas are such an idiotic, navel-gazing, Javascript hipster douchebag convention.