Next generation's garbage RSS 2.0
# Saturday, November 10, 2007

Everyone knows exception handling is relatively expensive, but it is important to keep in mind where the cost lies. It is primarily in the throw action. The price of a try is nearly zero when no exceptions occur.

In the IL instruction stream the only difference between a wrapped block of code and plain is a LEAVE instruction that jumps around the catch block. The method has an exception table that marks the region of code protected. What happens when we actually time the difference? The result is extremely small -- and strangely enough, try/catch in the loop is slightly faster for C#! Because the numbers we are dealing with are so small, however, I would suggest that this is coincidental noise due to instruction alignment or something like that. I would guess that the cost of try is essentially crushed out by the JIT compiler optimizer.

The real expensive operation is throwing exceptions. How expensive? My tests show it's about 36 microseconds each. Slow by comparison, but maybe not as slow as you thought. As expected VB's exception handling was a little bit slower (~1%), due no doubt to SetProjectError calls that are inserted before throws/rethrows.

I always had an assumption that THROW (rethrow) was cheaper than THROW ex or THROW NEW. I reasoned that the stackframe would not have to be gathered during rethrow. Timing it shows rethrow is slightly slower.

I learned you have to be pretty careful about timing code. For example, a significant amount of time is burned JITing when a function is hit the first time, and that first exceptions are really expensive. Firsts should be burned off before timing begins.

Try out the code attached and post your results and please give environment.

Here's my numbers on a Dell Latitude D830 1.7GHz 64-bit laptop w/ 4GB RAM.

>CSharp.exe 10000000000 100000
trycount=10,000,000,000, throwcount=100,000
Loop without try/catch: 31132 milliseconds
Loop with try/catch: 21251 milliseconds
difference: -9881 milliseconds
throw new with 5 throw ex: 21448 milliseconds
throw new with 5 rethrows: 21370 milliseconds
difference: 78 milliseconds

>VB.exe 10000000000 100000
trycount=10,000,000,000, throwcount=100,000
Loop without try/catch: 23361 milliseconds
Loop with try/catch: 30739 milliseconds
difference: 7378 milliseconds
throw new with 5 throw ex: 21617 milliseconds
throw new with 5 rethrows: 21845 milliseconds
difference: -228 milliseconds

Attached: TestExceptionHandlingInLoop.rar (12.5 KB)
Saturday, November 10, 2007 1:59:25 PM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
.NET Internals
# Sunday, November 04, 2007

blogging from my iPhone

Sunday, November 04, 2007 11:15:53 PM (US Mountain Standard Time, UTC-07:00)  #    Comments [1] -

# Friday, November 02, 2007

Scenario: You just made a nice DVWP and you exported it and mounted it on another page and kaboom -- FAIL.

Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.

Whoops. Different site. Even though the DVWP references the list by GUID, it doesn't work cross-site. Here's how to fix that.

Leave the broken DVWP where it is. Add another DVWP on the same page, in the Data Source Library, click "Connect to another library..." and point it at the site where the data came from. You should now be able to expand the lists/libraries and insert that. Now, just grab the stuff inside <SharePointWebControls:SPDataSource> and copy that over the broken one's data source. Throw away the temporary web part and you should be good to go.

Friday, November 02, 2007 11:03:22 PM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
SharePoint

I thought I saw Heather Solomon blog about how to do this, but I couldn't find it to reference here. Anyway, I wasn't really excited about the way she described, so I tried something else.

The problem is that SPD doesn't want you to customize a publishing page. You can detach it from the page layout, but that's kinda lame.

Try this instead:

  1. Make a copy of the page where you want a custom DVWP added.
  2. Detach the copy from the page layout
  3. Edit that page in SPD.
  4. Add and customize a DVWP.
  5. You might have to add DVWP to the webpart gallery - go to root admin, web parts, add.
  6. Now, export that DVWP which you can do from the browser.
  7. Upload it to the webpart gallery
  8. Mount it on the page you started with; the one that is still attached to the page layout.

Edit: You can short cut that a bit - after export, just go to the advanced toolpane, and import from there.

Friday, November 02, 2007 4:39:05 PM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
SharePoint

Yes, yes, I hear you anti-table zealots, but this is cool. (I'll have to blog my thoughts about this someday, along with the other religious argument about nothing but stored procedures accessible to code.)

Scenario: You have a table that will have n columns, where n is determined at run time and you want the columns to have equal width, for example, a table that is 100px wide with 4 columns should render 25px wide columns, 5 wide, 20px.

Why is this useful? SharePoint or ASP.NET SitePath menus.

Here's how:

table tr td { width:5%; }

When the table renders and sums up the 5%s and gets only 20 or 25% total, it scales that up to be 100% and the cell width percentage scales up with it.

see it at http://hafthor.com/equalwidthtables.html

I haven't tested this non-quirks mode, but it does work in FireFox and IE7.

[Edit 2007-11-04] I have tested this in xhtml strict mode (IE7 and FireFox) - it still works.

see it at http://hafthor.com/tricks.html

[Edit 2007-11-05] Dang. FireFox doesn't render this the way I wanted when in xhtml strict mode. The issue wasn't apparent until the overall width wasn't really wide. But, I tried those pages on iPhone Safari and they looked okay.

Friday, November 02, 2007 2:30:28 PM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
HTML | SharePoint
# Wednesday, October 31, 2007

I had a goal to get MCPD by the end of this month. I knew it was going to be tough given I had a 40hr/wk job to go to, but since my wife+baby where going to be out of town for a couple of weeks, I thought that this would be the ideal time block to get this done.

Two weeks ago I booked an exam time for today and bought the MCPD Training Kit from Borders and started reading. I was studying for the 70-551 which is the upgrade from MCAD to MCPD WebDev exam, but the kit is for the three individual exams that actually make up the 70-551.

It was a stretch, but I managed to read all three books cover to cover; well, sort of. I skipped the reviews and exercises. I also installed the training programs and went through the entire lesson review quiz type dealie. Last night I was going to go through that again and I thought to try the 'certification mode' on the training program. I didn't bother before because I thought it was the same stuff, just timed and only 45 random questions, and I thought it better to be thorough. Well, no, the questions were completely different. Some seemed to ask about stuff I never heard of. Panic. I stayed up nearly all night to race through the random certification mode a couple of times and find what they were talking about a study for it. Had I seen this the day before, I would have rescheduled the test for sure. I found out today that you can customize certmode to show everything like lesson review mode. (I thought selecting the customize tab was taking me back to the lesson review content.)

Anyway, I managed to get pretty comfy with the MCTS content, but just didn't have much time spent with the MPCD part. It was also the case that I rushed the MCPD content during the main study, as it was the last book and I basically read it Sunday afternoon to evening.

Result? FAIL! 4 hours gone.

Yep, I failed, but just barely. Apparently, the 70-551 is independently scored in three sections. You're given over an hour for each section and they are timed independently, but fail any section and you fail the whole thing. In trying to read the sheet with bars on it for the individual sections, it looks like I got 3 wrong out of 30 on the 70-528 part, 3 out of 28 wrong on the 70-536 but I must have gotten 10 wrong out of 30 on the 70-547 part since my score was 670. Ouch. Dang. Had I just gotten one more right, I would have squeaked by. Glad I registered for the free "second shot". What's odd is that in flipping through the 70-547 book, little in it looked familiar, as in, I don't remember that stuff on the test. There was several completely novel bits on the test, like how to use SetAccessRuleProtection. Stuff I searched the book for but didn't find. I might stumble upon it if I run the certmode a few more times. Another oddity is that the bar for the 70-547 looks more like 730 - yes, I measured it.

For those of you thinking about taking any of these tests, I would still say don't wuss out and shape test your way through it, but make sure you try the custom 'certification mode' before you take your test!

This is not the same experience that I had with the older MCAD related ones. They matched up pretty good with the topics discussed in the MCSD/MCAD training kit.

By the way, the comment period, where you can give feedback about questions, is 15 minutes total for all three sections -- and it takes about three minutes to advance to the next section. It said it would pause the timer between sections, but I'm not so sure. I didn't get a chance to comment any of the last section. Twice during the 70-547 part, advancing to the next question took a minute; literally 60 seconds. I should get a freebie question for that. :)

Anyway, I will spend my free retake soon.

Wednesday, October 31, 2007 8:08:41 PM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
Certification
# Saturday, October 20, 2007

Wow. Take a look at PhotoSynth [http://labs.live.com/photosynth] – Imagine if this was taken worldwide. I'm imagining an image-based positioning – your pictures could get automatically geo-tagged and if they were in a public collection you could find other images of that location. Virtual Earth integration… I wonder how related to the VE local image system this is. Based on shadows/star placement, it could even derive the time of day/night. Of course, most digital cameras know what time it is. What if they could stitch in the time dimension to it, so I could take a series of pictures outside and tween the series and play a movie of grass growing. This could also be useful for someone trying to edit an element out of a photo, by finding another photo shot from a transformable location without the element. Imagine a cloud of little unstable flying drones that swarm an area, take pictures and PS builds a world that you could walk through in virtual reality. Perhaps image enhancement based on several images of roughly the same thing. What about doing this to video? Stitch together a 3-D movie of an event from a hundred spectators' camcorders. Yeah, wow.

Saturday, October 20, 2007 4:09:46 AM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
From the labs
# Friday, October 19, 2007

Okay, there are many things I like about Office 12. There are many things I'm not so crazy about. The ribbon is chief among them.

"But you'll get used to it." Really, how far beyond a year straight will it take?

To me, it suffers from the same bummer as personalized menus do… location isn't consistent.

Look below. Okay, pretend I'm John Scherer and I'm trying to tell you where to find "Insert Category". The ribbon is okay, but geez, did you have to take away the menu bar? the old school toolbar? I feel marched.

"But it's more discoverable!" Or is it? I cannot rollover to see what's under "insert" or "add-ins" or "paste", "spelling", "publish" or styles past #11.

Cannot customize it without writing code? Are you kidding me?

Seriously, was backwards compatibility that much of a burden? You kept Lotus slash commands and help for WordPerfect users for umpteen years but you won't keep _the_ way from v.Last?

"But we've maintained keyboard shortcut compatibility for you experts." Uh, no. Alt+F,V doesn't give me print preview, Alt+O, enter doesn't get my font dialog. I gave up after that.

"But it's worth it because it automatically switches ribbons to show you commands related to your action" - so, the UI becomes unpredictable... tell me, what was so horrible about the little floating on-demand toolbars?

Please Microsoft, admit failure and bring back the pdm.

There are several companies selling what looks like the old ui on the ribbon, like this one that I'm trying out now (http://pschmid.net/office2007/ribboncustomizer/index.php) but I cannot do rollover exploration of the menus in it and it doesn't fix the keyboard shortcuts - Alt+F doesn't show me the Classic UI File menu. Doesn't look like it can be drag-drop customized or support mounting / docking toolbars.

Beyond the ribbon, context sensitive help seems to be totally broken. If you can't do context sensitive help, well, fine. Google, I'm feeling lucky.

Those are my biggest gripes.

Friday, October 19, 2007 12:54:00 AM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
Office 12
# Thursday, October 18, 2007

The first blog entry I made, initially, had a float clear problem. DasBlog apparently doesn't clear floats from the HTML entry contents in the crazy manner needed to appease the IE quirks gods. See http://www.positioniseverything.net/easyclearing.html.

The problem should be evident on this page:

http://hafthor.com/floatclear.htm

scroll down far enough on IE and you should see the text of the article disappear. This appears to happen because the align=right img floats lower than text. If you don't see that behavior, the image at the end of this article shows the effect. After posting the original article, I moved the image up to avoid this problem. But I wanted to see if I could fix it. Maybe...

http://hafthor.com/floatclear2.htm

I simply added this to the theme.css

.itemBodyStyle:after {
    content: ".";
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
}

.itemBodyStyle {display: inline-block;}

/* Hides from IE-mac \*/
* html .itemBodyStyle {height: 1%;}
.itemBodyStyle {display: block;}
/* End hide from IE-mac */

and got rid of the <div style="clear:both;" /> business from the itemTemplate.blogtemplate.

If this works right, I shouldn't have the float problem on this post.

Edit: Yes, but it doesn't work quite right when shown in RSS Bandit.

Edit: But if I place a <div style="clear:both" /> at the end of the blog article html, it shows up correctly. Hmmm...

Thursday, October 18, 2007 2:25:02 AM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
dasBlog | HTML

Last month I was working with some code that used System.Xml.Xsl.XslCompiledTransform. I knew it involved compiling stuff (where did I get that idea?) and making some IL dynamically to run. Neat-o. This month on my road to getting MCPD by month-end, I was reading about RegEx. It didn't really dawn on me before that it could compile the expression vs. interpret it. Pretty cool. But I was always skeptical about these because I had heard that you can Assembly.Load, but there's no such thing as Assembly.Unload... so I thought that this meant these would be memory leaks... but, no. I read (http://blogs.msdn.com/joelpob/archive/2004/04/01/105862.aspx) about something called LGC (lightweight code-gen) and DynamicMethod. I was reading this (http://blogs.msdn.com/bclteam/archive/2004/11/12/256783.aspx) and read that memory leak saga about regular expressions but "We've fixed that problem in Whidbey" caught my attention. They did? Yes, DynamicMethod does by making it so code can be emitted and executed from the managed heap - very cool. I had to know if XslCompiledTransform used this, so I reflected across Microsoft.*.dll and System.*.dll to see what uses DynamicMethod... Yes, XslCompiledTransform does. Nice - but I'm not sure it uses that exclusively. Given it actually spits out .dll files, I have to assume it Assembly.Loads and executes them... We avoided any potential leaks in a web app by holding the tranforms in the Application dictionary. This also made the whole thing faster since each transform was only compiled once.

By the way, I would encourage .NET devs out there to look in to getting certified (MCTS or MCPD). Don't be a wuss and shape-test your way through. (Shape-test refers to the process of getting test guides that so exactly mirror the real test that you can just memorize the shape of the correct answer to ace it. - I bet if given those kind of study guides written in Thai, I could pass the test. That's bull-khrap.)

Thursday, October 18, 2007 1:42:13 AM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
.NET Internals | Certification
# Wednesday, October 17, 2007

Well, after much procrastination, I finally spent some quality time with the GoDaddy hosting control center and various dasBlog instructions and got it working.

For anyone trying the same...

  1. From GoDaddy, go to "My Hosting Account".
  2. Click the [open] link under "Control Panel" for the domain.
  3. Under settings, select ASP.NET runtime and make sure it's 2.0.
  4. Under settings, check FrontPage extensions and make sure they are NOT installed.
  5. Select "Directory Management" under "Content".
  6. Create a custom directory where you'll host the blog with "Read", "Web" and "Set Root".
  7. Create the subdirectories SiteConfig and logs and give them each read+write access.
  8. Create another one called content and give it read+write+web access.
  9. Download the dasBlog webfiles zip and extract it locally.
  10. Edit your siteconfig/site.config setting the obvious looking stuff.
  11. Edit your /web.config to get rid of or comment out the line
    <trust level="Medium" originUrl="" /> (a GoDaddy-ism)
  12. Copy all the extracted files to your blog directory (using explorer view on ftp:// works)
  13. Point your browser at your blog.
  14. Sign in using "admin", "admin" (unless you changed the user name in SiteConfig/siteSecurity.config before you uploaded it)
  15. Immediately change that password.

** Disclaimer: I didn't try those steps exactly so they may not be entirely perfect. **

Edit: Okay, I just setup another blog using those instructions and they seemed to work nicely.

Look here for more help on this.

http://www.aakashjain.com/How+To+Setup+DasBlog+On+Godaddy.aspx

Now, to blog from Word 2007 with images… create from the blog post template, set up an account of type "Other" and set the Url to http://domain/blogdir/blogger.aspx, set the picture option to "my blog provider". Publish! It should automatically upload pictures to /content/binary/.

Okay, so what is freachable? It is purgatory for .NET objects with finalizers. During garbage collection, objects that have finalizers need to have their finalizers run, but the GC shouldn't have to wait for them (after all the entire process is stalled while GC runs and finalizer code could affect what the GC is doing), but if there are no references to keep the object alive, it will get collected so the object is made to reachable by the finalizer thread by placing it in its special queue called freachable. GC completes and the finalizer thread wakes up, executes the finalizers in the freachable queue, and clears the queue entry, which is the last remaining reference to the object and now the next time GC runs, the object's memory will be reclaimed.

Read all about GC at http://msdn.microsoft.com/msdnmag/issues/1100/gci/

According to that article, it is pronounced f-reachable. That just sounds l-ame.

So what's the point of this blog? To blog stuff I figure out. I will try not to waste bandwidth on "hey, go read what this other guy figured out". Okay, so most of this post is stuff that someone else figured out, but the web.config mod on dasBlog was not in Aakash's notes.

Wednesday, October 17, 2007 11:53:53 PM (US Mountain Standard Time, UTC-07:00)  #    Comments [0] -
.NET Internals | dasBlog | Office 12
Archive
<November 2007>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678
All Content © 2010, Hafthor Stefansson - Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way. - Sign In