Hi, I'm Ron Cormier. I'm the owner of a small software company where I design websites and build reusable web applications.

This blog is a work in progress but I plan on writing about website development, software design, information technology, and some of the projects I'm working on for Communicate Solutions. Check out my company's website, Communicate Solutions.com.
Sign in

Tags


Chrome has V8 engine Chrome logo

A couple months ago I wrote about how Google may be pushing its new Chrome browser by making changes to google.com.  Having done a lot of work in JavaScript recently, it got me wondering how Chrome intended to actually speed things up.  It turns out the key is their new JavaScript engine, V8.

V8 is the code name of the JavaScript virtual machine shipped with Chrome.  It is named V8 because it is supposed to be powerful like and 8 cylinder car engine.  I did some googling and found a video where the V8 tech lead, Lars Bak, explains how it is fast.

 

Why is V8 fast?

There are primarily three techniques V8 to improve the speed of execution of JavaScript in Chrome:
1. Hidden Objects
If two objects of the same type are created, a third, hidden object is created which links the two child objects.  The key reason for doing this is that it helps generate efficient machine code.

2. Dynamically generated machine code
When V8 parses your JavaScript, it doesn't generate an intermediate byte code as most engines do.  Instead, it generates native machine code (assembly).  This is much faster since there is no interpretation step.

3. Precise garbage collection
Lars says that memory is reclaimed incrementally so there are minimal pauses or hiccups in the browser when using a complex JavaScript application.

 

When is it not fast? 

As Lars explains in a MSDN Expert to Expert video, V8 is optimized for the most common JavaScript programming patterns and operations.  If your JavaScript program uses infrequent operations, V8 could experience very slow performance.  An example of an operation which could slow things down is deleting/re-adding object properties.  V8 is standards compliant, so it will work but it might not be fast.  "If you write that kind of code, we want to penalize you", mentions Lars with a chuckle.  He also goes on to say that this is how it works in the initial version and it could be changed in future version.

 

The Verdict

V8 and Chrome definitely sound cool.  Lars doesn't strike me as an architecture astronaut so the future looks bright.  However, the technology is so new that I wouldn't yet recommend it for most users.  Honestly I haven't tried it out yet myself.  I'm pretty happy with Firefox and especially all the extensions that are available for Firefox.  I am planning to run my web app's test cases in Chrome in the near future... I'll be sure to post the results.

 

Bonus JS Architecture Talk

Can't get enough?  Check out this talk given by Ryan Dahl at the 2009 European JavaScript Conference.  Ryan describes NodeJS, a server-side JavaScript platform built on V8 which features purely asynchronous I/O and event loop concurrency.  The main program never waits on I/O... giggity.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

This is Part II of a two-part series on WYSIWYGs.  In Part I, we covered what WYSIWYGs are and how they work.  In this article we'll look more closely at what happens when you save your changes and why they butcher/maim/ruin your code.

As mentioned in Part I, when it is time to save your document, the DOM gets translated to HTML and can then be saved to file or database.  The document is typically an inline frame (iframe) located within another web page.  Let's assume the iframe has the following HTML:

<html>
<body>
    <p>this is a test paragraph 1</p>
        <p>this is a test paragraph 2</p>
</body>
</html>
 

There's a few different ways to translate the DOM rendered by the browser to HTML which can be saved.  One way is to get the frame's innerHTML. Assuming the WYSIWYG is in the first inline frame, you can use the following javascript:

alert(window.frames[0].document.body.innerHTML);

innerHTML using Internet Explorer

 

Executing the above javascript in Internet Explorer would show a dialog like the one to the right. 

This method is handy for most situations.  The problems begin when you care about the markup that you originally wrote.  For example, notice any differences between the dialog to the right and the HTML snippet above?  One big difference is the paragraph elements are capitalized in the image even though they weren't capitalized in the HTML.  What the heck?!?  Another difference is the white space gets ignored when getting the innerHTML.  The second paragraph should be indented when compared to the first paragraph.  Annoying!!  Firefox is guilty of changing the markup too.  While Firefox is better at retaining white space, it changes all HTML tags from uppercase to lowercase.

This can be a nightmare.  Image you've spent some time developing a website with an IDE like Visual Studio or Dreamweaver.  Want your clients to be able to update the content themselves?  Well as soon as they do an update with the WYSIWYG, they're going to completely destroy your code's readability.  When you try to look at the code after your client's update, it could be completely different.  This is unacceptable.

I've decided to design a WYSIWYG that is friendly to both technical and non-technical users.  Whenever the client makes a change in the WYSIWYG, the change also gets reflected in the code without messing up the code.  This is done by maintaining a copy of the code along side the WYSIWYG.  Formatting stays the same.  Capitalization stays the same.  The code actually looks the same before the WYSIWYG update as after.  Imagine that?  No patience necessary :)

To see it in action, check out v1.6 of ePortfolio, the CMS for ASP.Net developers (coming soon!).  

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Thursday's New York Times' Decoder article struck a cord with me.  In the article, Sergey Brin defends Google's stance on non-search-related topics like scanning out-of-print books, Microsoft, network neutrality, and Chrome.  Google's motto is to "not be evil" but lately I have to question their methods.

Chrome is clearly something that Google is pushing hard.  Google.com is my homepage and I've frequently seen the ads pushing me to try Chrome because it is so much faster.  I use Firefox (v3.5.3) and lately I've noticed that google.com is much slower to load.  In the last few days, it seems like the page is loading differently; the logo and the search box appear immediately and the other links 'fade in' a few seconds later, like after I move my mouse.

I suppose it's possible that Google thinks they are making improvements to google.com.  Maybe it is a better design in the long run.  I'm not sure I buy that though.  Right now it is clunky and annoying.  It seems more likely to me that Google is incorporating fancy (and unnecessary) Javascript into their site and don't care if it runs slowly on Firefox.  After all, supposedly Chrome's big advantage is its Javascript performance, right?  Is this the right way for a company to push its agenda?

On this subject, I say ok.   As a website developer, Javascript performance is important to me and this may be Google's way of forcing the issue.  The point is that there clearly is an agenda here which needs to be scrutinized and shouldn't be overlooked because of their friendly motto.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5