Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Do comments negatively affect performance? 2

Status
Not open for further replies.

Gooser

Technical User
Jun 28, 2006
803
0
0
US
Do comments negatively affect performance in a stored procedure?

I don't think they do, but haven't been able to find any proof either way yet. (still looking)

From my understanding MS SQL Server doesn't actually execute the stored procedure, per se, but rather executes the optimized execution plan created from the blueprint the stored procedure provides. Therefore I would assume that other than at first-compile time when the comments have to be 'skipped over', there could be no performance issue. Am I correct in this assumption?

Even so, how costly could this possibly be?

Any insight into this would be greatly appreciated.

Thanks,
v/r

Gooser

'Why do today
that which might not need to be done tomorrow?' --me

 
No performance issues that I am familiar with.

The only problem with comments is that they make life much simpler for the person following you. :)

Since months after you wrote something, you may have to do some additional work, the person following can be you!






 
Oh, I totally believe that comments are the right thing to do, we just have a contractor claiming they affect performance. [nosmiley] I think that is total BS and he is just trying to shirk the responsibility of having to comment his code, so I am looking for proof that comments do not significantly affect stored procedure performance.

Thanks for the support, though.

v/r
Gooser


 
I just tested this. Here's how...

I created a stored procedure:

Code:
Create Procedure [dbo].[TestWithoutComments]
As
Select 1 As TheValue

Code:
CREATE Procedure [dbo].[TestWithComments]
As
[green]/*

Approximately 150 kb of comments, essentially a bunch of copy/pastes to get something large.

*/[/green]
Select 1 As TheValue

Then....
Code:
Declare @Start DateTime

Set @Start = GetDate()
exec TestWithComments
Select DateDiff(Millisecond, @Start, GetDate())

Set @Start = GetDate()
exec TestWithoutComments
Select DateDiff(Millisecond, @Start, GetDate())

Even with 150 kb worth of comments, the 2 stored procedures ran in the exact same time. Stored procedures are compiled in to the database. Since it's compiled, the comments are stripped out (just like any other programming language).

However, if you are executing dynamic SQL from a front end app that sends direct commands to the database (without using stored procedures) and the command includes lots of comments, then there will be some network bandwidth used to send the comments. Since you are using stored procedures, this is absolutely NOT the case.

Basically, comments do NOT affect the performance of running a stored procedure.

I sometimes take contracting jobs (albeit rarely). When the 'person with the money' requests something that I don't agree with, I state my opinion and then I always add... "It's your decision, I'll implement this anyway you want. I just wanted to point out another view point".

If your contractor insists on NOT commenting the code, it's probably time to find another contractor.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
George said:
...it's probably time to find another contractor.

I couldn't have said it better myself. [nosmiley]

how about a table aliased as o0 (that's oh-zero) without using the keyword AS?[ponder]

...a column that holds 388 for all 58,267 rows?[ponder]

...every varchar in the database is varchar(512)![neutral]

...orphaned conditional logic...if the ELSE will never-ever fire, get rid of the if/else altogether![evil]

...a column name like this:
class_i_i_i_flammable_liquid_charge_lookup_key_nm_item_cd_value
or this:
risk_component_section_part_type_item_cd_value?[ponder]

And I haven't even gotten into the details of the model.[mad]

--frustrated in Seattle
Gooser








 
Even IF it does affect performance (which it is not), comments must still be used. Nobody wants to inherit huge lines of code without a single trace of comments. Simple things like date, number of updates, who's doing the update, reason for update, etc etc will greatly help.

Example: people still put comments on dBase III+ prg files, even though every chars (comments or not) will have effects on the app's performance (since it was basically an interpretter, not a compiler).

As for that contractor, if he sticks with his arguments (and if you can't afford to replace him) you must ask him to compensate the lack of comments with proper technical documentation.

 
Just a note:

I have made a good living the last 3 years as a contractor.

Mostly fixing this type of persons code when no one else will take the project.

So his practices do have some value :)

I do feel sorry for some of the clients though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top