Silverlight Hack

Silverlight & related .NET technologies

About Me

Welcome to Silverlighthack.com.  This is a site where you can find many articles on Silverlight, Windows Phone 7 and .NET related technologies.  

My name is Bart Czernicki.  I have been working with computers since 1988 and have over 12 professional years in the IT field focusing on architecture, technology strategy and product management.  I currently work as a Sr. Software Architect at a large software development company.

Below is the cover of my new book that shows how Silverlight's unique RIA features can be applied to create next-generation business intelligence (BI 2.0) applications.

Silverlight 4 Business Intelligence Soft 

Contact: bartczernicki@gmail.com

View Bart Czernickis profile on LinkedIn

NONE of the comments or opinions expressed here should be considered ofmy past or current employer(s).  The code provided is as-is without anyguarantees or warranties.

Silverlight & ASP.NET MVC vs Web Forms (Very High Level)

Silverlight 2 RTW has been out for a couple of weeks now and it is already being compared to ASP.NET MVC which is an evolutionary way to design web applications using ASP.NET.  I read a concise summary (pros and cons) of ASP.NET MVC from Jason Young.  His article can be read here: http://www.ytechie.com/2008/10/aspnet-mvc-pros-and-cons.html

I decided to compare Silverlight in a similar way to what Jason did when he compared ASP.NET MVC vs. Web Forms.

Here are the items he listed as ASP.NET MVC vs. Web Form:

PROs vs. ASP.NET Web Forms

  1. No ViewState or "surprise crap"
    • This applies to Silverlight as well.  Silverlight brings the "desktop" experience to the end user and there is no ViewState that is used in Silverlight.
  2. Faster server-side & client-side
    • Silverlight is faster on the client/server side depending on how you look at it.  Silverlight is compiled in a .NET subsystem of Silverlight.  You have access to multithreading, LINQ, complex data structures, etc.  The performance vs. an ASP.NET or AJAX/JavaScript application is it magnitudes times better because of the client execution and some of the items that normally are handled in a server BLL can be brought down to the client
  3. Simplified model for multiple related views
    • Silverlight supports the complete seperation of the data and the UI.  Taking this further by just creating seperate views for say another consumer of Silverlight is pretty powerful.  You can apply the same MVC/MVP pattern inside Silverlight and attain this level of abstraction.  Jason mentions an example of being able to create a seperate view for an iPhone and only the View component has to change.  This applies to Silverlight as well for different things.  For example, I have large sized Silverlight app I want to port to SharePoint.  I can create a "Smaller View" for SharePoint so it fits nicer into the UI.  Furthermore, Silverlight Mobile is being private tested now.  I would assume that same very powerful level of abstraction applies as well to create a "Mobile view" for your Silverlight application.
  4. Unit Testable
  5. Challenges if you are not running IIS 7
    • Silverlight does NOT care if you are not running on IIS 6 or IIS 7 or Apache for that matter.  This is one feature where Silverlight has an advantage over ASP.NET MVC.
  6. Client Caching
    • In ASP.NET Web Forms or MVC, you are caching on the server.  Silverlight allows you to cache on the client via Isolated Storage (which can be increased to hundreds of megs if necessary).  This allows applications to perform ultra fast without bogging down the hosting server.

 

CONs vs. ASP.NET Web Forms

  1. Difficult to convert existing code
    • Silverlight is a completely different programming platform than either ASP.NET WebForms or MVC.  Not only will a lot of the code not convert, you also have to think about the client layer and in most cases a complete re-architecture is needed if you are replacing large modules inside your existing ASP.NET site.
  2. NOT the best SEO out of the box
    • Google several months ago started spidering SWF files and adding them to the search engine.  I think Silverlight is probably still a ways away here.  What you can do for Silverlight SEO is the basic tricks to describe the meta data tags really well around the plug in.
  3. Data access
    • Data access in Silverlight is limited to Web Services/WCF/ADO.NET Data Services.  You cannot make direct calls via ADO.NET or stored procedures to a database.
  4. Security
    • Silverlight runs on the client.  A lot of your bits are then roaming in the wild on the internet.  Furthermore,  some of the data access techniques do not support full WS* standard security.  Therefore, beyond certificate based transport security, you are either writing a lot of your own plumbing code or waiting for the next rev.  The XAML code is pretty much insecure; not many applications have their Intellectual Property in their UI.  In Silverlight, that can be very easily reverse engineered using Silverlight Spy for example. Silverlight, just by nature, is a little less secure than an ASP.NET MVC application.  Obviously, you would want to encrypt/obfuscate your Silverlight assemblies before letting them off in the wild.

In conclusion, even though Silverlight and ASP.NET MVC are two completely different technologies, they share A LOT of the same pros and cons Jason pointed out vs. Web Forms.  The only difference is that the hosting model for Silverlight is a lot simpler.  Silverlight does have its nuances with data access and security that you have to worry about.  Furthermore, you do get other benefits like client-side performance and client-caching.

kick it on DotNetKicks.com
Posted: Oct 23 2008, 07:51 by Bart Czernicki | Comments (1) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: Silverlight
Tags:
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

Silveright 2 GUIMark - Big Performance Boost in Silverlight 2 RTW

10/23/2008 Update:  Updated the code (rendering and MaxFrameRate) and some notes below  
 
GUIMark  Background 

Silverlight has had a few iterations since the Silverlight 1.1 Alpha Days.  We started at Silverlight 1.1 Alpha in 2007.  This year we had two beta releases and RC0 before Silverlight 2 RTW was released.  Silverlight and JavaFX are two new RIA technologies that were introduced this year competing with Adobe's Flash/Flex.  In comparing the different technologies, it is natural to compare the performance of the different RIA products and their AJAX/Java Applet cousins.

One of the big performance indicators was GUIMark. GUIMark is a performance test designed by Sean Christmann to gauge the performance of the rendering subsytem of the given technologies.  One of the claims of this benchmark is that it uses a variety of tests to give a more true test of the rendering pipeline.  There are a variety of different visuals that truly test the performance of the rendering engine.  No test is perfect, but I found this one to be pretty good.

GUIMark and Silverlight 2 Beta 1 & 2

I have been playing with Silverlight off and on in the Alpha 1.1 days and since Beta 1, a lot more.  I came across the GUIMark site several months ago and was pretty disappointed with the results with the Silverlight rendering engine.  Looking at the site you can see that Silverlight 2 Beta 1 had a HORRIBLE performance of about 7-8 frames/second.  It even lagged behind Silverlight 1.0/JavaScript!  Flex/HTML was many factors ahead in performance (30-40/FPS).

Silverlight 2 Beta 1 at the time the results were published the technology was obviously not finished.  Why was the rendering so poor?  Alex Grenier in the GUIMark website pointed out that the text rendering was the bottleneck.  Sure enough, I tried the test myself and removing the text rendering resulted in Silverlight dramatically having the same FPS as Flex.  Microsoft obviously had some work to do in order to improve the text rendering for Silverlight.

GUIMark and Silverlight 2 RTW Code

Silverlight 2 RTW has been out for a couple of weeks now.  GUIMark has not updated the source code since Beta 1 so I decided to upgrade the code and see how how the performance has increased.  I essentially took Sean's Silverlight Beta 1 code and upgraded it for Silverlight 2 RTW in its bare essentials.   (The code can be downloaded below)

  • I updated the dependency properties to use double data types instead of ints.
  • After Beta 1, Silverlight apparently does not support binding from an object that is subclassed from the DependencyObject. You can read more about this here: http://silverlight.net/forums/t/13593.aspx  To me, this is really weird and it is worth a discussion outside this topic.
  • I changed the namespace and added a web project for deployment and testing
  • I did NOT TOUCH the rendering loop which is totally inefficient and can now leverage the Silverlight 2 RTW.  This can easily add several FPS to the project. See the 10/23 update below, I updated the rendering loop to use the CompositionTarget.Rendering

Silverlight 2 RTW Performance Test

In one of the changes from the betas to RC0/RTW was the text glyph rendering.  We knew this was a bottleneck before, lets see how well this performs now.  The best way to judge the performance is to see the code run yourself.  Click the links below to run the test.  Open each link individually and make sure nothing processor intensive is running.  If you click the "Run Test" button, just click it once to receive an average FPS over 10 seconds.  (If you keep clicking Run Test, the test will fail).

Results - On my Vista Dual Core IE 7 (Your results will vary depending on your processors and browser):

  • Flex 3: ~43 FPS
  • Silverlight 2 RTW: ~43 FPS (updated code with MaxFrameRate set to 500)

The performance is almost identical between Silverlight and Flex.  Microsoft definitetly fixed the rendering of text glyphs.  That change is primarily responsible for the great performance improvement.  Remember that render loop still can be improved (I might do an update to the code) for extra FPS.  One thing to note about FPS is that in a normal production system, FPS is ususally limited.  In Flash/Silverlight, the default is about 60 FPS.  A lot of developers/architects (including myself) limit the FPS even further.  The human eye can't tell the difference between 40-60 FPS anyway, so trying to eke out 400 FPS is completely uncessary.

Silverlight 2 RTW Code: SilverlightHack_GUIMarkSilverlight2RTM.zip (795.85 kb)

10/23/2008 Update

I updated the code to use the new CompositionTarget.Rendering event which is new in Silverlight 2 RC0/RTW.  This is the best practice for things such as gameplay loops.  Some people noticed that Flash was performing siginigantly better than Silverlight.  I thought it was the rendering loop being inefficient,  however this change by itself did not change the FPS at all.  This rendering loop is directly tied to the MaxFrameRate which can be set programatically at runtime by setting the Application.Current.Settings.MaxFrameRate property.  Playing with this increased the Silverlight FPS by 15!

The default for the MaxFrameRate is 60.  That means that if you have no code or little code if you just put a FPS counter you will get 60 FPS (I tested that and that works fine).  Obviously, if you have code in your loop that code could potentially drop.  So, I updatd the code/demo with a Frame Rate selector to show what is happening here.

  • Setting the MaxFrameRate 10-40 the FrameRate increases.  (for example if I set it to 10, I get 10 FPS)...all this makes sense
  • Setting the MaxFrameRate 40-60 the FrameRate drops to 35 FPS.  This is probably because of the increased overhead of the events.  This kind of makes sense.
  • Setting the MaxFrameRate 60-500 the FrameRate increases up to 46 FPS ???  This is really weird.  I don't understand why setting the FrameRate to 500 actually nets the best results.  To me this doesn't make sense.

I posted this question on the Silverlight.net forums here: http://silverlight.net/forums/p/41045/115696.aspx#115696 (When I get an answer, I will update this post)

This does some interesting questions on the MaxFrameRate setting.  Oviously one thing I can say 100%...if you are writing a Silvelight game or heavy animations, you need to be very aware of this setting for performance.  Furthermore, if writing any benchmarks for Silverlight you may want to play with the optimal MaxFrameRate setting in order to get the best possible results.

kick it on DotNetKicks.com
Posted: Oct 21 2008, 11:05 by Bart Czernicki | Comments (14) RSS comment feed |
  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: Silverlight
Tags:
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

Silverlight and the Enterprise

Silverlight: Feature Complete

Silverlight 2 released and the feature set has been locked down for a while now.  Many RIA experts, bloggers and developers have chimed in on forums or blogs on what features they would like to see in Silverlight and the direction it should take.  Opinions vary greatly on this and by doing a simple search online you can see the vast differences.  While I definitely agree this needs to be discussed, I feel that there is so much that Silverlight 2 currently offers that future features can be disucussed later.

Microsoft is taking a nice approach with Silverlight 2 in that they are going to be releasing additional Silverlight assemblies outside the core download.  The nice result of this is that we don't have to wait any longer for the releases to come out [Silverlight 2 (1.1 Alpha) was announced March 2007!].  Furthermore, by not bloating the core with additional features, this keeps the Silverlight 2 client payload pretty small (around 4.6 megs).  The first example of this "add-on" strategy is the new Silverlight controls project from Shawn Burke.  Microsoft will also release "professional themes" for Silverlight the same way.  Both of these and more will probably be released at the PDC 2008 this month.  Instead of adding value in Silverlight by directly building features into the core, a lot of value can be built by building "around" Silverlight.

Competitive Environment: Next Generation Web

Many are already calling the end of Web 2.0. The internet is on the brink of new type of services and software that will be released under the Web 3.0 umbrella.   Many companies including Google, Microsoft, Apple, Firefox, Adobe, etc., are positioning themselves in their offerings for the upcoming new generation of products.  When Silverlight 2 is released, it will put Microsoft in a VERY unique position.  Microsoft's main competitors in the technology are Adobe (Flash/Flex/AIR) and Sun (JavaFX).  However, Microsoft has many more competitors especially with more and more core OS features moving to the web and the mobile space.  Google and Apple would be Microsoft's big competitors there.  However, neither Google nor Apple have a RIA technology that they own themselves (Apple's iPhone UI tech is proprietary to the device for now).  Microsoft is a lot bigger than all of these companies individually; however, each of their individual companies can cause problems for Microsoft in their vertical strengths.  There is one thing that Microsoft can do that none of these companies can do invidually: integrate a new UI/RIA technology in their vast horizontal of business & enterprise products (mainly because none of these companies has that enterprise product penetration).  This not only would add value to Microsoft's products, but it also would add value to Silverlight indirectly.  For example, this can position Silverlight as business RIA technology and Silverlight doesn't have to play catch-up in the graphical area with Adobe (PhotoShop, Illustrator, 3D acceleration, etc.).

Silverlight in the Enterprise

How can Silverlight be used in the Microsoft enterprise space?  Here is a mix of existing and potential ideas where I think Silverlight can be a great addition to the presentation stack:

Parallel Computing

Silverlight is powered by the subset of .NET 3.5.  Although Silverlight 2 will not allow everything in multithreading (i.e., true async delegates), it does have a decent baseline which a developer can utilize.  Any current computer that has been purchased within the last couple of years includes a dual core processor.  Intel is planning on releasing 6 core processors later this year.  By not utilizing parallel computing, you're not maximizing the efficiency of the program and all the processing it could utilize.  Microsoft is very aware of the shift to multiple cores and has invested in this with their parallel computing initiative.  This library includes additions to make LINQ execute on multiple threads by simply adding the AsParallel() extension method on the end of your LINQ query.  A parallel extensions library for Silverlight does not exist right now.  However, adding this simple abstraction to Silverlight would be a huge boost to performance and would allow some enterprise level applications to be scaled down to the data level on the client.  In my previous multithreading articles I mimicked some of the basic flow of the parallel tasks and gained up to 120% performance improvements!  Enterprise architects will be able to take a serious look at Silverlight as a potential powerful "client tier" to potentially offload some simple to medium cost processing and reduce trips to the server or reduce service calls.

SharePoint 2007 Integration

SharePoint is one of Microsoft's fastest growing products in terms of adoption and revenue.  In my opinion, allowing the developers to focus on designing/developing content and not focusing on "plumbing code" is probably the best feature of SharePoint.  This allows businesses in the enterprise to quickly set up the SharePoint farm and deliver content quickly.  Silverlight is a great UI technology to extend SharePoint.  During the SharePoint 2008 Conference, Microsoft announced the Blue Print for SharePoint Services.  These blue prints are meant to provide guidance for building SharePoint solutions that include Silverlight.  This addition is huge for Silverlight because this technology can now be utilized in one of Microsoft's biggest enterprise offerings.  I have done several solutions inside SharePoint 2007.  One of the things that it missed was true AJAX integration until SP1.  Even now, some things like cross web part communication cause postbacks and then one has to deal with the "statless web" workarounds.  The Silverlight plug-in is a great way for extending the SharePoint experience in a more interactive way that AJAX can simply not do.  Furthermore, Silverlight can access many of the SharePoint features such as Lists, work flows, etc., via SharePoint services. If you are a SharePoint developer, I am sure I don't have to go into the potential that Silverlight and SharePoint integration provides.

Windows Communication Foundation

WCF is a true SOA framework for building enterprise level services.  Microsoft is one of the few companies that has a deep SOA framework such as this.  Currently Silverlight only supports basic HTTP services, WCF REST services and a duplex version.  Similarly to SharePoint, the biggest feature of WCF is that it allows you to focus on designing services rather than "plumbing code".  WCF abstracts a lot of complexity of enterprise messaging while allowing you to make decisions in which you can stay in the "best practice" realm.  WCF makes creating an enterprise service easy.  For example, using the WSHttpBinding, binding the service is secure, faults propegate across services, integrates with authentication, reliability can be configured, etc.  This is a truly powerful feature.  A lot of WCF bindings are not available to be consumed in Silverlight because that would mean including a lot of the core .NET 3.0 libraries that would bloat the core payload.  Hopefully external libraries are made available for Silverlight in the future that would allow consuming WS standard bindings.  In my opinion, the further integration of Silverlight and WCF is going to help propel Silverlight as a powerful, interactive consumer of enterprise services.

SQL Server

SQL Server has come a long way since I first started using the 6.5 version.  It now includes enterprise reporting (Reporting Services), a true ETL engine (SSIS) and a powerful Buiness Intelligence OLAP engine (SSAS); although it's not OLAP anymore.  One of the things that has been lacking with Reporting Services and Analysis Services is the presentation layer for both the end user and the respective product administrators.  Microsoft is aware of this which is shown with Microsoft's recent acquisition of ProClarity or SQL Server 2008 SSRS visualization additions.  All of these products also have a "techy" look and feel with their tools because of the integration with the Visual Studio 200x shell which needs to be installed on the local workstation.  This is where I think Silverlight can come in and extend a lot of the presentation or even the administration features of these SQL Server products.  Silverlight is perfect because it is a web technology and it allows for deep interaction with the data.  Therefore, there is nothing to install beyond the plug-in, but you can still enjoy a desktop experience.  For example, imagine opening a Reporting Services report and going beyond static data and being able to do "what if" scenarios or bringing key insight to life with animations.  Silverlight with SQL Server can definitely bring the data to life in the enterprise.

Mesh, Semantic Web and Cloud Computing

 

Silverlight RIA UI + Cloud Computing Data + Semantic Web =

Microsoft is making a big play in the new Web 3.0 realm: cloud computing, semantic web and bringing the dekstop experience via the web.  Microsoft has a variety of services: Outlook Online, SharePoint Online, Exchancge Online, Mesh and other various data services.  The problem with these are that they have the classic Microsoft business look and are not 100% intuitive for non-business users.  This is where Microsoft has a huge edge with Silverlight.  Merging the power of these services together with a super-rich and easy to use interface can make these services wildly popular.  What other company can do this on a massive scale?  Apple has shown that people en masse will go for an advanced UI.  Microsoft can build on this with already popular products and services in the backend.  This brings us a lot closer to the Minority Report type interface but with actual meaningful data behind it. 

Who cares about a pretty UI if it's just an intro for a corporate site or a movie site?  Silverlight and the Microsoft cloud computing platform can change this.

Bringing in data and the UI together is a very powerful combination that will bring a more dynamic UI and lets the user decide how the data is presented, viewed and analyzed.  In my opinion, this is Microsoft's best shot at usurping Google in their game. This platform has the potential to be Web 3.0.

In conclusion, in this article I wanted to cover a couple of important concepts relating to Silverlight in the Enterprise.  The main concept I wanted to describe is that just because Silverlight 2 is feature complete doesn't mean the technology cannot grow in value.  Microsoft owns the enterprise market and this is where I think a technology like Silverlight cannot only add value to the enterprise offerings but the enterprise offerings can make Silverlight a first-class RIA technology for business.  Silverlight does not have to play catchup with Adobe Flash/Flex and can lead in business/enterprise product innovation.  In my opinion, "the Silverlight Enterprise Ace" is a card that Microsoft can play in the next few months and increase the popularity of Silverlight dramatically.

kick it on DotNetKicks.com
Posted: Oct 19 2008, 16:03 by Bart Czernicki | Comments (3) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: Enterprise | Silverlight
Tags:
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us

Ensure sure your Silverlight Beta 2 code works past this week!!!

Microsoft has released Silverlight 2 and will be making the Silverlight 2 RTM plug-in available to the masses.  What does this mean?  Any Silverlight version (Beta 1 and Beta 2) will be automatically upgraded to Silverlight 2 probably this week.  Silverlight Beta 2 compiled assemblies will NOT WORK with Silverlight 2 RTM.  This will most likely be fine for most people that simply were learning the Silverlight product.  However, if you have a Beta 2 application in any form in production, live for demos, used by sales or have consulting clients, etc., you need to either upgrade your code or you're screwed, right?  Not necesarily.

First, if you are in this boat, you have just learned the power of setting up an isolated demo environment (i.e., Virtual Appliance).  If you do not have this luxury and can control some or all of the client machines, you can still prevent your beta 2 app from not working.  Simply turn off the auto updates for Silverlight temporarily until you are ready to upgrade to Silverlight 2.

  1. Right click on any Silverlight application and select "Silverlight Configuration"
  2. Select the "Updates" Tab
  3. Ensure that "Install Updates Automatically" is not checked
    1. The option you chose here depends on the user or yourself.  For example, you can set it to never update (then you have to make sure you don't forget to update to SL 2 RTM) or you can say prompt for updates, but you also want to make sure the user won't accidentaly click Yes.  So either of these are fine. 

This will work great if you have an Intranet solution and control the machines.  However, if you have a beta 2 application out for the masses (internet), there is no way this would work.  This can buy you some time to get the application up to RTM standards and then simply tell your consumers to update the Silverlight plug-in.

Other tip:  Before uninstalling beta 2/RC0 and go full force with RTM development, ensure you have the proper tools.  Remember Expression Blend is not free, so you can either use your company's/personal MSDN subscription or it's time to purchase the software.  You don't want to lock yourself into an upgrade nightmare.  I also highly recommend Expression Design for prototyping.

kick it on DotNetKicks.com
Posted: Oct 13 2008, 10:21 by Bart Czernicki | Comments (6) RSS comment feed |
  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Filed under: Silverlight
Tags:
Social Bookmarks: E-mail | Kick it! | DZone it! | del.icio.us