473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

C# Performance question

In our business frameworks we are creating objects off of the heap to
represent every small value such as a CustomerNumber. We will have thousands
of these small objects in an application at any one time. These objects are
very thin as most of the members have been declared static.

I proposed to my team that we use the flyweight design pattern to
significantly reduce the number of small objects we have in memory. This
will not be a simple modification so the rest of the team understandably
wants me to justify my decision. I don't know how; it's just based off of my
gut that the current practice is bad. I have reverse engineered the .NET
Framework and found that they are using the flyweight pattern to represent
column values within rows, which is effectively the same thing I am up
against. They must have had a reason to do this.

Am I wrong? Can .NET effectively handle tens of thousands of objects? If my
argument has merit, how can I prove it to the rest of the team? I tried
Googling this, but I did not have much luck.

BTW, the current implementation has other faults. For example, using mutable
reference objects to represent values has horrid side-effects. A lot of you
probably know this, so please don't let that distract you from the performan
question.

Thank you for your time.

Respectfully,

Bill O'Neill
Oct 21 '06 #1
3 1235
Bill O'Neill wrote:
I proposed to my team that we use the flyweight design pattern to
significantly reduce the number of small objects we have in memory. This
will not be a simple modification so the rest of the team understandably
wants me to justify my decision. I don't know how; it's just based off of my
gut that the current practice is bad.
Am I wrong? Can .NET effectively handle tens of thousands of objects? If my
argument has merit, how can I prove it to the rest of the team? I tried
Googling this, but I did not have much luck.
I can not see a problem by having tens of thousands of objects.

Indeed I would expect many apps to have hundreds of thousands of
objects.

Note that I am not saying that usage of flyweight design pattern
in your case is a bad idea.

But tens of thousands of objects in itself does not justify it.

Arne
Oct 21 '06 #2
On Sat, 21 Oct 2006 08:38:34 -0600, "Bill O'Neill" <bi***@cu.net>
wrote:
>Am I wrong? Can .NET effectively handle tens of thousands of objects? If my
argument has merit, how can I prove it to the rest of the team? I tried
Googling this, but I did not have much luck.
Do you experience actual performance issues, such as intermittent
noticeable pauses when the garbage collection runs, or even disk
thrashing when the swap file is accessed? Is rapidly increasing
memory use restricting the lifetime of an application instance?

Or do you expect the flyweight implementation to reduce the memory
load so much that some computationally intensive algorithm might run
entirely within the CPU cache?

If neither of those is true you probably won't get much benefit from a
new implementation. .NET itself certainly doesn't have a problem with
tens of thousands of objects.

The CLR team has to pick very efficient algorithms because they're
creating a library that's used in applications of all kinds and sizes.
But in your case, if I understand you correctly, you're already
looking at the actual working set of a complete application. In this
case I would keep the alternative in mind but not bother to implement
it unless there's an actual performance issue.

By the way, you can use Microsoft's CLR Profiler to monitor your
application's use of managed memory:
http://msdn2.microsoft.com/en-us/net.../aa569269.aspx
--
http://www.kynosarges.de
Oct 21 '06 #3
Bill O'Neill <bi***@cu.netwrote:
In our business frameworks we are creating objects off of the heap to
represent every small value such as a CustomerNumber. We will have thousands
of these small objects in an application at any one time. These objects are
very thin as most of the members have been declared static.

I proposed to my team that we use the flyweight design pattern to
significantly reduce the number of small objects we have in memory. This
will not be a simple modification so the rest of the team understandably
wants me to justify my decision. I don't know how; it's just based off of my
gut that the current practice is bad. I have reverse engineered the .NET
Framework and found that they are using the flyweight pattern to represent
column values within rows, which is effectively the same thing I am up
against. They must have had a reason to do this.
Well, in some situations the flyweight pattern can be useful, but that
doesn't mean it always is. Thousands of objects can easily be handled
by .NET - particularly if they're short-lived, and thus never get out
of generation 0.
Am I wrong? Can .NET effectively handle tens of thousands of objects? If my
argument has merit, how can I prove it to the rest of the team? I tried
Googling this, but I did not have much luck.

BTW, the current implementation has other faults. For example, using mutable
reference objects to represent values has horrid side-effects. A lot of you
probably know this, so please don't let that distract you from the performan
question.
Mutable reference types have their downsides, but mutable value types
are worse, IMO. So long as you *know* a reference type is mutable, it's
often the right way to go, particularly if the value is likely to
change frequently.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Randell D. | last post by:
Folks, I have a Javascript performance question that I might have problems explaining... In PHP, better performance can be obtained dealing directly with a variable, as opposed to an element...
115
by: Mark Shelor | last post by:
I've encountered a troublesome inconsistency in the C-language Perl extension I've written for CPAN (Digest::SHA). The problem involves the use of a static array within a performance-critical...
4
by: Martin | last post by:
I am using graphics as backgrounds for forms,buttons,labels etc. The question is: is it faster to load all graphics from files on app start or to use it embeded (places in editor during design)....
13
by: bjarne | last post by:
Willy Denoyette wrote; > ... it > was not the intention of StrousTrup to the achieve the level of efficiency > of C when he invented C++, ... Ahmmm. It was my aim to match the performance...
6
by: Mike | last post by:
Lets just say my app is done HOO HOO. Now, I'm accessing the database via a web service and one thing i noticed that my app is running real slow. When I first started working on the app is ran...
18
by: Rune B | last post by:
Hi Group I was considering using a Generic Dictionary<> as a value container inside my business objects, for the reason of keeping track of fields changed or added and so on. - But how...
5
by: Varangian | last post by:
Hi, I have a performance issue question? which is best (in terms of efficiency and performance, I don't care neatness in code)... building an ArrayList of Object Instances using SqlDataReader...
5
by: Markus Ernst | last post by:
Hello A class that composes the output of shop-related data gets some info from the main shop class. Now I wonder whether it is faster to store the info in the output class or get it from the...
5
by: toton | last post by:
Hi, I want a few of my class to overload from a base class, where the base class contains common functionality. This is to avoid repetition of code, and may be reducing amount of code in binary,...
30
by: galiorenye | last post by:
Hi, Given this code: A** ppA = new A*; A *pA = NULL; for(int i = 0; i < 10; ++i) { pA = ppA; //do something with pA
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.