This blog has moved to Medium

Subscribe via email


Archive for November 2008

Avoid expensive ToString() calls in log4net

premature optimization is the root of all evil.” (Donald Knuth)

And, if I might add: “ugly optimization is not so great either”.

We have some classes with rather expensive ToString() methods in our code base. When used in logs (specifically, log4net), we incured the performance penality even when the logging level (Debug/Info/Warn/…) was too low, and the log wasn’t even printed. In other words, ToString() was called before the log method, in order to build the single string that is the input parameter to Logger.Log().

Our ugly optimization was to add checks before every log line, as in:

if (logger.IsDebugEnabled)
   logger.Debug("Calling " + someObjectWithExpensiveToString);

A better solution, which I just tested to work, is to use the …Format() family of methods. This way, you pass objects and not strings, which are then only converted to strings if there is a need.

logger.DebugFormat("Calling {0}", someObjectWithExpensiveToString);

The following test assures me it actually works:

ILog logger = LogManager.GetLogger("Foo");
ToStringCounter counter = new ToStringCounter();
Assert.AreEqual(0, counter.ToStrings);
Assert.IsFalse(logger.IsDebugEnabled);
 
logger.DebugFormat("Expecting zero ToString() calls: {0}", counter);
Assert.AreEqual(0, counter.ToStrings);

Where ToStringCounter is simply a class that counts the number of calls to its ToString() method.

Magic draft walkthrough creator

If you’re into magic and enjoy drafting through Netdraft, check out my new walkthrough creator (this is a sample walkthrough of Shards of Alara I’ve made through it).

Shards of Alara draft Walkthrough (Jund)

I haven’t found any walkthrough yet for Shards of Alara, so I wanted to write one, even though I only drafted the set a couple of times and only on Net Draft. I also noticed that many draft walkthrough I see are not visual, so a person who doesn’t know the new set yet has to find the cards to understand what’s going on. A little bit of programming, and I created the Magic Draft Walkthrough Creator – anyone can just upload a saved replay from Net Draft and get a full visual walkthrough template. So without further delays, here is my humble first walkthrough for a Shards draft.


Pack 1

Pick 1

Skill BorrowerJund BattlemageGrixis CharmGrixis BattlemageCall to Heel
Bant PanoramaJund PanoramaBloodthorn TaunterDeft DuelistVithian Stinger
Bone SplintersWild NacatlObelisk of EsperRelic of Progenitus
Spoiler:
My pick: Jund is a very strong clan, and I've seen some Devour 2 creatures get to 10/10. Grixis Charm is sweet but not a first pick here.
Jund Battlemage

Pick 2

Tidehollow ScullerProtomatter PowderAlgae GharialMarble ChaliceOnyx Goblet
Obelisk of NayaCourier's CapsuleGustrider ExuberantJungle WeaverExecutioner's Capsule
Lush GrowthJund PanoramaBone Splinters
Spoiler:
My pick: Nothing in this pack beats the efficiency of Executioner's Capsule. While less powerful with all the multicolored spells, Dark Banishing it still very good (even if it's not a pure instant)
Executioner's Capsule
.

Pick 3

Bant BattlemageKiss of the AmeshaAngel's HeraldRip-Clan CrasherSavage Hunger
Obelisk of GrixisSigil BlessingWindwright MageObelisk of EsperThorn-Thrash Viashino
Goblin DeathraidersObelisk of Naya
Spoiler:
My pick: Probablly not strictly the best card in the pack, the Devour 2 on Thorn-Thrash Viashino looks promising. A couple of turns worth of the battlemage, and this baby will be huge.
Thorn-Thrash Viashino

Pick 4

Gather SpecimensKiss of the AmeshaOnyx GobletObelisk of NayaSoul's Might
Coma VeilAngelsongCarrion ThrashCloudheath DrakeObelisk of Esper
Soul's Grace
Spoiler:
My pick: I like to grab in-color obelisks whenever I can. This builds a strong mana base and opens the possibility for a fourth color if I see anything worth while. Besides, nothing else in this pack I want.
Obelisk of Naya

Pick 5

SwerveVolcanic SubmersionTidehollow StrixGustrider ExuberantGoblin Deathraiders
Dregscape ZombieRip-Clan CrasherMosstodonResounding WaveShadowfeed
Spoiler:
My pick: Mostodon is a solid pick, it triggers the various 5-power goodness if I happen to grab any and it's single green mana makes it easier to put other heavy color cards in, knowning I'll always be able to cast something while waiting for my colors.
Mosstodon

Pick 6

Vicious ShadowsEsper CharmSangrite SurgeMighty EmergenceDeathgreeter
Tortoise FormationYoked PlowbeastAngelsongCarrion Thrash
Spoiler:
My pick: In retrospective it's possible I should have picked Sangrite Surge to go on some flyer I pick up, but here I chose the solid but otherwise unexciting Carrion Thrash (although one has to remember it plays along with Devour to bring back your dudes)
Carrion Thrash

Pick 7

Rockcaster PlatoonVolcanic SubmersionResounding ScreamBant PanoramaShadowfeed
Jungle WeaverObelisk of EsperDispeller's Capsule
Spoiler:
My pick: Another mistake here, going to a double-white 7 CC creature instead of the in-color cycler Jungle Weaver. Live and learn.
Rockcaster Platoon

Pick 8

Behemoth's HeraldSunseed NurturerCathartic AdeptSoul's MightShadowfeed
Yoked PlowbeastGuardians of Akrasa
Spoiler:
My pick: Nothing good in this pack, so I continue my excursion into white with the cycler.
Yoked Plowbeast

Pick 9

Skill BorrowerCall to HeelJund PanoramaBloodthorn TaunterDeft Duelist
Relic of Progenitus
Spoiler:
My pick: I take the obvious fixer here, I don't care much for haste-givers and it can't power up Devour creatures if it's sacrificed to them.
Jund Panorama

Pick 10

Protomatter PowderMarble ChaliceObelisk of NayaGustrider ExuberantLush Growth
Spoiler:
My pick: Nice! A 10-th pick obelisk in my colors. This might make it possible to splash white if want.
Obelisk of Naya

Pick 11

Angel's HeraldSavage HungerObelisk of EsperObelisk of Naya
Spoiler:
My pick: Woot, another obelisk. I just can't get enough, though I probablly won't play them all.
Obelisk of Naya

Pick 12

AngelsongObelisk of EsperSoul's Grace
Spoiler:
My pick: I take yet another one, it has two of my colors if I decide to include white. Not sure it will happen, but Angelsong doesn't seem to do a lot for my deck.
Obelisk of Esper

Pick 13

Volcanic SubmersionShadowfeed
Spoiler:
My pick: Less trashy card.
Volcanic Submersion

Pick 14

Tortoise Formation
Spoiler:
Tortoise Formation

Pack 2

Pick 1

Goblin AssaultRockcaster PlatoonDawnray ArcherJund CharmCavern Thoctar
Steelclad SerpentGrixis PanoramaCathartic AdeptCall to HeelJund Panorama
Court ArchersTidehollow StrixVithian StingerSigil Blessing
Spoiler:
My pick: I'm conflicted on Goblin Assault, yet another Jund-enabler (even though its critters might die easily). Still, 2 damage to everything at instant speed plus the versatility makes it impossible not to pick Jund Charm.
Jund Charm

Pick 2

Puppet ConjurerDawnray ArcherGrixis CharmBanewasp AfflictionWild Nacatl
Tortoise FormationVithian StingerElvish VisionaryDreg ReaverSoul's Might
BlightningDruid of the AnimaHissing Iguanar
Spoiler:
My pick: Another mistake, I took the druid here over the stinger. How many fixers must a man play? The druid is not a bad card for me, but the pinger trumps it and combos with other damage dealers I will have.
Druid of the Anima

Pick 3

Sprouting ThrinaxNaya BattlemageNaya PanoramaAngelsongViashino Skeleton
Deft DuelistShadowfeedCylian ElfRidge RannetWelkin Guide
Undead LeotauObelisk of Naya
Spoiler:
My pick: Another Jund bomb - 3 mana for a combined 6/6, that can be sacrificed for much profit. Naya battlemage is another solid card here, but I have some good removal so I can live without the tapper.
Sprouting Thrinax

Pick 4

Invincible HymnExuberant FirestokerObelisk of BantTidehollow StrixDruid of the Anima
Cloudheath DrakeCourt ArchersDispeller's CapsuleThorn-Thrash ViashinoBlightning
Deft Duelist
Spoiler:
My pick: Now that's what I'm talking about. All this draft I'm waiting for more Thorn-Thrash Viashno, and here they come. This is a kind of multilpication thing - take enough of factor A (token generators) and enough of factor B (strong devourers) so you reap the huge benefits.
Thorn-Thrash Viashino

Pick 5

Rhox ChargerBant CharmScavenger DrakeObelisk of EsperDeathgreeter
Kederekt CreeperResounding RoarComa VeilElvish VisionaryBone Splinters
Spoiler:
My pick: I have a lack of fliers, and this guy will grow large fast if I start eating up my other dudes.
Scavenger Drake

Pick 6

Thoughtcutter AgentGrixis BattlemageAkrasan SquireSoul's FireRip-Clan Crasher
AngelsongGrixis PanoramaShore SnapperGodtoucher
Spoiler:
My pick: I'm assuming I'll always have some kind of body, so this will mostly be a 3-CC instant removal for at least 2-3 damage.
Soul's Fire

Pick 7

Thoughtcutter AgentRockcaster PlatoonSteelclad SerpentObelisk of EsperBlister Beetle
Goblin DeathraidersShore SnapperDreg Reaver
Spoiler:
My pick: Removal - you grab it even if it's medicore or worse.
Blister Beetle

Pick 8

Bant BattlemageShadowfeedThorn-Thrash ViashinoBlister BeetleCourt Archers
Kathari ScreecherHindering Light
Spoiler:
My pick: Lucky 3rd Viashno. These guys will party.
Thorn-Thrash Viashino

Pick 9

Rockcaster PlatoonDawnray ArcherCavern ThoctarSteelclad SerpentCathartic Adept
Call to Heel
Spoiler:
My pick: I don't have too many high CC creatues, and this one fill the curve with a fat 5/5 body.
Cavern Thoctar

Pick 10

Dawnray ArcherBanewasp AfflictionTortoise FormationDreg ReaverSoul's Might
Spoiler:
My pick: Nothing here is playable, so I cut the stronger card.
Dawnray Archer

Pick 11

AngelsongViashino SkeletonShadowfeedRidge Rannet
Spoiler:
My pick:
Ridge Rannet

Pick 12

Invincible HymnExuberant FirestokerDispeller's Capsule
Spoiler:
My pick: I'm unsure if I'll have enough large creatures, but it's playable and it produces mana (albit colorless).
Exuberant Firestoker

Pick 13

DeathgreeterComa Veil
Spoiler:
My pick:
Coma Veil

Pick 14

Thoughtcutter Agent
Spoiler:
My pick:
Thoughtcutter Agent

Pack 3

Pick 1

Punish IgnoranceQasali AmbusherNaya CharmInfestResounding Silence
Deft DuelistObelisk of JundRakeclaw GargantuanCathartic AdeptJund Panorama
Kederekt CreeperWaveskimmer AvenSoul's FireGoblin Deathraiders
Spoiler:
My pick: Some tempting cards here, from Naya Charm (a strong finisher, but I'm not sure I'm white), and Qasali Ambusher which just looks cool but again is off my colors. Then I see Infest - dillema over.
Infest

Pick 2

Jund BattlemageExuberant FirestokerBull CerodonSteward of ValeronShore Snapper
Jungle WeaverObelisk of BantDeft DuelistThorn-Thrash ViashinoBanewasp Affliction
Kederekt CreeperRip-Clan CrasherJhessian Lookout
Spoiler:
My pick: First card in the pack, first pick. Another battlemage to feed the hunger.
Jund Battlemage

Pick 3

Cunning LethemancerRockcaster PlatoonAlgae GharialJhessian InfiltratorGustrider Exuberant
Volcanic SubmersionComa VeilSanctum GargoyleAngelsongSigil Blessing
Carrion ThrashRidge Rannet
Spoiler:
My pick: Nothing exciting here, so I pick the 4/4 body.
Carrion Thrash

Pick 4

Esper CharmAngelic BenedictionWelkin GuideCavern ThoctarDispeller's Capsule
MosstodonGuardians of AkrasaVolcanic SubmersionCourt ArchersResounding Roar
Cancel
Spoiler:
My pick: I don't have too many combat tricks, and even without the cycling option this is nice.
Resounding Roar

Pick 5

Lich's MirrorExuberant FirestokerSwerveVectis SilencersCarrion Thrash
Viscera DraggerLush GrowthMarble ChaliceShore SnapperDeft Duelist
Spoiler:
My pick: I won't play a 3rd Carrion Thrash, so I settle for another Firestoker.
Exuberant Firestoker

Pick 6

Banewasp AfflictionExcommunicateVectis SilencersEtherium SculptorObelisk of Bant
Steelclad SerpentKederekt CreeperCavern ThoctarJhessian Lookout
Spoiler:
My pick: While not the best of removals, it takes care of anything and I have some critters I wouldn't mind sacing, including token saporlings.
Cavern Thoctar

Pick 7

Cradle of VitalitySigiled PaladinBlood CultistSighted-Caste SorcererLush Growth
Wild NacatlDruid of the AnimaKnight of the Skyward Eye
Spoiler:
My pick: A late blood cultist!
Blood Cultist

Pick 8

Memory ErosionRockcaster PlatoonEtherium AstrolabeBone SplintersShadowfeed
Obelisk of BantElvish Visionary
Spoiler:
My pick: In-color obelisk to complete my collection.
Bone Splinters

Pick 9

Punish IgnoranceDeft DuelistObelisk of JundCathartic AdeptKederekt Creeper
Goblin Deathraiders
Spoiler:
My pick:
Obelisk of Jund

Pick 10

Shore SnapperObelisk of BantThorn-Thrash ViashinoBanewasp AfflictionJhessian Lookout
Spoiler:
My pick: Another Viashino, I've lost count already.
Thorn-Thrash Viashino

Pick 11

Rockcaster PlatoonGustrider ExuberantComa VeilAngelsong
Spoiler:
My pick:
Angelsong

Pick 12

Angelic BenedictionDispeller's CapsuleCancel
Spoiler:
My pick:
Angelic Benediction

Pick 13

Vectis SilencersMarble Chalice
Spoiler:
My pick:
Marble Chalice

Pick 14

Banewasp Affliction
Spoiler:
My pick:
Banewasp Affliction

Sadly I don't have war stories or the deck I ended up building, I didn't think I'd be writing a walkthrough. Will do better next time.
* This walkthrough was created by Create Your Own Magic Draft Walkthrough

I’m missing StackOverflow

It’s down and it hurts (signs of a successful website).