Monday, July 1, 2013

Context Switching: An Example

Last week at #kscope13 I saw an outstanding example of context switching. If you don't know what it is, Tom Kyte explains it here.

The two environments are just "different", separate and distinct. You can do plsql without SQL, you can do SQL (and many times do) without invoking plsql. There is a call overhead to go from SQL to PLSQL (the "hit" is most evident when SQL invokes PLSQL - not so much the other way, when SQL is embedded in PLSQL). Even if this hit is very very small (say 1/1000th of a second) - if you do it enough, it adds up. So, if it can be avoided - it should be.

The session was Using Kanban and Scrum to Increase Your Development Throughput presented by Stew Stryker (not to be confused with Ted Striker) of Dartmouth College (Stew gave me a gallon of Vermont Maple Syrup which exploded in my bag on the flight home, a gift for sharing my hotel room. Thanks Stew! ;)). So here's the example he gave to demonstrate context switching.

Take a list of names and time yourself writing out the first letter of each name, then the second, until you are finished.



Now, same list of names and write them out the way you normally would, left to right.



If the first method was faster, you are a freak of nature.

2 comments:

amy c said...

It was a fantastic exercise! For me, this example wasn't tied directly to "context switching" in the PL/SQL and SQL sense, but in general how much it "costs" to not have focus on getting one thing done. Excellent exercise and session in general!

Stew said...

Thanks Amy! I really enjoyed the group discussion that got going. As I said, I learned in the Scrum Master training class by Scrum, Inc.

Chet, it would have been just as effective, but much cheaper, had I bought you a gallon of Aunt Jemima, put it in a good jug, left some air in it, then let you transport it home! I hope the ants stop following in your footsteps soon! :-)