r/programming • • Dec 20 '10

A Christmas Tree in 1k of Javascript

http://www.romancortes.com/blog/how-i-did-the-1kb-christmas-tree/
1.1k Upvotes

221 comments sorted by

View all comments

42

u/ImTheGuyWithTheGun Dec 20 '10 edited Dec 20 '10

Amazing how much smoother this runs in Chrome compared to Firefox. And IE8 - forget about it.

EDIT: Safari 5 seems even worse than Firefox. My system is a core-i5 w/ 6GB on Win7 - should be plenty of horsepower.

21

u/rickmatt Dec 20 '10

I loaded it in Firefox 3.6.13 (on a 64 bit quad core desktop with 6G RAM running Windows 7 Ultimate) and my CPU usage went from 1% to 25%. Closed it and usage dropped to 1% again. Loaded it in Chrome and there was no appreciable increase in usage. WTF?

3

u/whoisrich Dec 20 '10

For anyone wanting to try FireFox 4 there is a portable edition here:

http://portableapps.com/apps/internet/firefox_portable/test

The Reddit comments load so much faster compared to Firefox 3.

8

u/[deleted] Dec 20 '10

I don't know what could cause that but i'm suspecting that hardware acceleration has a lot to do with it. It seems that javascript is one of the things that is fully output with software only. If there was hardware acceleration then it would be blazing fast.

It's like trying to render out a 3d game with software (ie. CPU only). It doesn't matter what computer you use, it's going to get crushed trying to spit out those polygons. But on hardware acceleration it's all offloaded onto the GPU which is specially designed to handle just such things, which is how we enjoy things like that these days.

15

u/ascendant512 Dec 21 '10

I was forced to register because of this thread and some comments in it. The Chrome fanboys here are quite ridiculous.

Chrome does not have hardware-accelerated javascript. Hardware-accelerated javascript does not exist. You are mistaking it with WebGL which is present in Safari, Firefox (3 and 4) and Chrome. WebGL has nothing to do with javascript, it is a hardware accelerated <canvas> element (HTML5). Chrome has barely any more hardware acceleration than Microsoft Powerpoint.

Furthermore, the Christmas tree is not rendered with polygons, it is rendered with sprites. It says so right on the front page.

5

u/[deleted] Dec 21 '10

hint: a sprite is a textured polygon. you can very much take advantage of hardware acceleration using just sprites.

Although i doubt this tree example uses any hardware acceleration.

→ More replies (14)
→ More replies (14)
→ More replies (9)

2

u/wefarrell Dec 21 '10

For js, chrome is several orders of magnitude faster than ff.

The ff beta is just as fast as chrome though.

4

u/abadidea Dec 21 '10

iirc the Mozilla Javascript team has said they're on track for catching up to Chrome. Chrome's JS has done to FF what Firefox did to the IE interface team several years ago: embarrass them into trying harder.

→ More replies (1)

15

u/Seandroid Dec 20 '10

This worked PERFECTLY on Safari 5 on my Mac.... it was smooth as butter.

9

u/causticmango Dec 21 '10

Must be specific to Windows. On OS X, Safari is noticeably smoother (for this demo, at least).

2

u/[deleted] Dec 21 '10

Not surprising, Safari probably uses HW acceleration for canvas on OS X, but not on Windows.

7

u/[deleted] Dec 20 '10 edited Oct 02 '26

[removed] — view removed comment

12

u/mrkite77 Dec 20 '10

chrome has incredible javascript performance. I made a 68k emulator in javascript that had no problem running at 1mhz on chrome.

6

u/feureau Dec 21 '10

I made a 68k emulator in javascript

... whoat?!

68k emulator in javascript

@_@

68k emulator in javascript

WANT!!!

→ More replies (3)
→ More replies (2)
→ More replies (20)

7

u/MironV Dec 20 '10

It actually runs fastest for me in IE9.

→ More replies (4)

7

u/krische Dec 20 '10

It was about the same speed wise for me in Firefox 4 beta 7 and Opera 11 as it was in Chrome.

6

u/ImTheGuyWithTheGun Dec 20 '10

I'm using FF 3.6.9. I know FF 4 supposedly has a much faster JS-engine -- good to hear that it's true. But in 3.6, it runs at a fraction of the framerate compared to chrome.

→ More replies (2)

5

u/longmover79 Dec 20 '10

Smoothest/Fastest award goes to Safari followed by Chrome then FF a significant last (on mine at least)

3

u/ImTheGuyWithTheGun Dec 20 '10

Safari is a slide-show for me (dual core on Win7). Firefox is better, but still jittery. Chrome is silky smooth.

6

u/cruzin Dec 20 '10

Safari and Chrome look the same for me: smooth, no jitters. I'm using OS X, not Win7 though.

5

u/[deleted] Dec 20 '10

Seconded, Safari and Chrome are pretty much neck-to-neck, with Safari being slightly faster (in my highly unscientific side-by-side comparison (OSX, i7)).

→ More replies (1)
→ More replies (1)

2

u/IllBeBack Dec 20 '10

In IE8 all I get is a javascript error.

2

u/[deleted] Dec 21 '10

Interesting. Safari 5 under OS X 10.6 is noticeably smoother than either Firefox or Chrome. And I have a pretty slow machine (2.16 GHz Core 1 Duo, Radeon X1600).

2

u/boran_blok Dec 21 '10

It runs fine in opera, but one core is pegged at 100% tho.

→ More replies (3)