shared methods in data access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am noticing that the methods in MS's data application block are all shared.
Any implications for performance with this? Seems like if users are sharing
methods, we could take some sort of hit if they are accessing the same
methods.


Thanks,

Dan
 
Not particularly and in some instances performance will be better. There
are a bunch of 'if's' on anythign dealing with performance, but there's
nothing about statics that make them perform worse in and of itself. If you
have 4 calls to SqlHelper for instance, then you're going to make 4 calls to
the db regardless of whether you do them in statics/shared or instance
methods. The real thing to focus on is CLOSING those connections as soon
as you're done with them and opening them as late as possible. Tuning your
queries on the db is another area that causes really performance drama. I'm
not telling you to blindly make stuff static but by and large, making
something static isn't going to cause you any inherent performance
problems --- but not putting your connections in a using block (fi you're
using C#), and not handling them properly - that can cause MAJOR problems.

HTH,

Bill
 
If you are getting an issue, you will have the same issue whether it is
static/Shared or an instance method, as the bog will be in the data pipe
rather than the method. I guess, theoretically, you could have an issue, but
the ADO.NET architecture is such that the calling connection and the actual
underlying connection are two different objects.

Shared saves you from having to instance the app block for each call,
reducing load time for the methods. The actual objects created and run are
lower down the stack.

Not sure if this is making sense, so the short answer is "I would not worry
about it at all".


---

Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************
 
Method code is never copied whether its an instance method or a static
(shared) method. The only difference between instance and static methods is
that for instance methods, the address of the instance is placed on the
stack before jumping to the address of the method code for execution so that
the instance data is available. So in terms of execution, instance methods
are no different from static methods. You shouldn't be worried about
performance in this case. As W. G. Ryan mentioned, its the DB hits that are
more of a performance hit and you should be focus more on optimizing your
queries, stored procs, etc

hope that helps..
Imran.
 
Back
Top