Do generic instantiations in multiple units bloat the executable?

Since discussion on SO for following post

http://stackoverflow.com/q/31684300/4267244

has outgrown the media, I am opening this thread to get
to bottom of things.

Rudy, can you post your console app project that shows increase
in exe size when you use TList<Integer> in different units?

-- 
Dalija Prasnikar
0
Dalija
7/28/2015 9:03:37 PM
embarcadero.delphi.non-tech 5933 articles. 1 followers. Follow

20 Replies
507 Views

Similar Articles

[PageSpeed] 21

> {quote:title=Dalija Prasnikar wrote:}{quote}
> Rudy, can you post your console app project that shows increase
> in exe size when you use TList<Integer> in different units?

Oh wow, this forum is still a thing.

Anyway, I could reproduce this in a simple test case on XE7.1: https://www.dropbox.com/s/7rrc5cdeqaj7dal/GenericCodeSize.zip?dl=0

HOWEVER, it only seems to be due to additional debug info, ie it only happens in Debug mode.

In Debug mode, for each unit I add the generic code to, the resulting exe file increases by about 10k.

In Release mode, for each unit I add the generic code to, the dcu increases from 1k to 39k, but the resulting exe file remains the same.

Cheers
- Asbjørn
0
Utf
7/28/2015 10:51:19 PM
Asbjørn Heid wrote:

> HOWEVER, it only seems to be due to additional debug info, ie it only
> happens in Debug mode.
> 
> In Debug mode, for each unit I add the generic code to, the resulting
> exe file increases by about 10k.
> 
> In Release mode, for each unit I add the generic code to, the dcu
> increases from 1k to 39k, but the resulting exe file remains the same.

It is also possible to check addresses of methods of the same generic
classes defined in different units: if theirs addresses are the same
than there is no real code bloating. (BTW, is there difference if
identical classeses are declared privately in implementation section?
Or if one class is in interface but another one in implementation?)

--
Alex
0
Alex
7/29/2015 5:21:10 AM
Asbjørn Heid wrote:

> HOWEVER, it only seems to be due to additional debug info, ie it only
> happens in Debug mode.
> 
> In Debug mode, for each unit I add the generic code to, the resulting
> exe file increases by about 10k.
> 
> In Release mode, for each unit I add the generic code to, the dcu
> increases from 1k to 39k, but the resulting exe file remains the same.

It is also possible to check addresses of methods of the same generic
classes defined in different units: if theirs addresses are the same
than there is no real code bloating. Or better compare theirs VMT
address with 'is' operator: identical classes should have the same
VMT address ('is' should return true).

BTW, is there difference if identical classeses are declared privately
in implementation sections of diffrerent units? Or if one class is in
interface but another one in implementation of another unit?

--
Alex

Edited by: Alex Belo on Jul 29, 2015 11:52 AM
0
Alex
7/29/2015 5:59:58 AM
Dalija Prasnikar wrote:

> Since discussion on SO for following post
> 
> http://stackoverflow.com/q/31684300/4267244
> 
> has outgrown the media, I am opening this thread to get
> to bottom of things.
> 
> Rudy, can you post your console app project that shows increase
> in exe size when you use TList<Integer> in different units?

The code is not here, so I can't post it now, but I assume it was what
Asbjørn found: additional debug info. And the addresses of methods in
different units are the same, I checked that.

So I was wrong. That is why I deleted my answer in SO.
-- 
Rudy Velthuis        http://www.rvelthuis.de

"They that die by famine die by inches."
 -- Matthew Henry
0
Rudy
7/29/2015 6:31:11 AM
> {quote:title=Rudy Velthuis (TeamB) wrote:}{quote}
> Dalija Prasnikar wrote:
> 
> > Since discussion on SO for following post
> > 
> > http://stackoverflow.com/q/31684300/4267244
> > 
> > has outgrown the media, I am opening this thread to get
> > to bottom of things.
> > 
> > Rudy, can you post your console app project that shows increase
> > in exe size when you use TList<Integer> in different units?
> 
> The code is not here, so I can't post it now, but I assume it was what
> Asbjørn found: additional debug info. And the addresses of methods in
> different units are the same, I checked that.
> 

Thanks for the info. I did extensive testing few years ago, and quick test
yesterday, but your discovery made me think I have missed something.

Since some of my apps have to be as small as possible that would not
be good news. 

I will do some additional testing later on. 

> So I was wrong. That is why I deleted my answer in SO.

You are seldom wrong in matters that are not opinion based, this is just one 
of those times ;-)

-- 
Dalija Prasnikar
0
Dalija
7/29/2015 7:58:27 AM
Rudy Velthuis (TeamB) wrote:

> And the addresses of methods in different units are the same, I
> checked that.

OK, thank you for information.

--
Alex
0
Alex
7/29/2015 8:27:44 AM
Dalija Prasnikar wrote:

> > So I was wrong. That is why I deleted my answer in SO.
> 
> You are seldom wrong in matters that are not opinion based, this is
> just one of those times ;-)

That is correct. And even my opinions are excellent. <g>

-- 
Rudy Velthuis        http://www.rvelthuis.de

"Smith & Wesson - the original point and click interface."
0
Rudy
7/29/2015 9:01:38 AM
Dalija Prasnikar wrote:

> > So I was wrong. That is why I deleted my answer in SO.
> 
> You are seldom wrong in matters that are not opinion based, this is
> just one of those times ;-)

That is correct. And even my opinions are excellent. <g>

-- 
Rudy Velthuis        http://www.rvelthuis.de

"Smith & Wesson - the original point and click interface."
0
Rudy
7/29/2015 9:03:12 AM
Rudy Velthuis (TeamB) wrote:

>  And even my opinions are excellent. <g>

And that is your opinion. <g>


[]s


Cesar Romero
0
Cesar
7/29/2015 5:12:35 PM
Am 29.07.2015 um 11:01 schrieb Rudy Velthuis (TeamB):
> Dalija Prasnikar wrote:
> 
>>> So I was wrong. That is why I deleted my answer in SO.
>>
>> You are seldom wrong in matters that are not opinion based, this is
>> just one of those times ;-)
> 
> That is correct. And even my opinions are excellent. <g>
> 

....at least in your opinion <g>
0
Markus
7/29/2015 6:52:44 PM
> {quote:title=Rudy Velthuis (TeamB) wrote:}{quote}
> Dalija Prasnikar wrote:
> 
> > > So I was wrong. That is why I deleted my answer in SO.
> > 
> > You are seldom wrong in matters that are not opinion based, this is
> > just one of those times ;-)
> 
> That is correct. And even my opinions are excellent. <g>
> 

Only when they coincide with mine ;P

-- 
Dalija Prasnikar
0
Dalija
7/29/2015 7:03:02 PM
Cesar Romero wrote:

> Rudy Velthuis (TeamB) wrote:
> 
> >  And even my opinions are excellent. <g>
> 
> And that is your opinion. <g>

And that is why it is excellent. <g>


-- 
Rudy Velthuis        http://www.rvelthuis.de

"The significant problems we face cannot be solved at the same
 level of thinking we were at when we created them."
 -- Albert Einstein (1879-1955)
0
Rudy
7/30/2015 10:20:52 AM
Markus Humm wrote:

> Am 29.07.2015 um 11:01 schrieb Rudy Velthuis (TeamB):
> > Dalija Prasnikar wrote:
> > 
> >>> So I was wrong. That is why I deleted my answer in SO.
> > > 
> >> You are seldom wrong in matters that are not opinion based, this is
> >> just one of those times ;-)
> > 
> > That is correct. And even my opinions are excellent. <g>
> 
> ...at least in your opinion <g>

And since my opinions are excellent...
-- 
Rudy Velthuis        http://www.rvelthuis.de

"In Germany they first came for the Communists,
 and I didn't speak up because I wasn't a Communist.
 Then they came for the Jews,
 and I didn't speak up because I wasn't a Jew.
 Then they came for the trade unionists,
 and I didn't speak up because I wasn't a trade unionist.
 Then they came for the Catholics,
 and I didn't speak up because I was a Protestant.
 Then they came for me -
 and by that time no one was left to speak up."
 -- Pastor Martin Niemöller
0
Rudy
7/30/2015 10:22:17 AM
Dalija Prasnikar wrote:

> > {quote:title=Rudy Velthuis (TeamB) wrote:}{quote}
> > Dalija Prasnikar wrote:
> > 
> > > > So I was wrong. That is why I deleted my answer in SO.
> > > 
> > > You are seldom wrong in matters that are not opinion based, this
> > > is just one of those times ;-)
> > 
> > That is correct. And even my opinions are excellent. <g>
> > 
> 
> Only when they coincide with mine ;P

Even if they don't.

-- 
Rudy Velthuis        http://www.rvelthuis.de

"Opportunities multiply as they are seized."
 -- Sun tzu
0
Rudy
7/30/2015 10:31:44 AM
Rudy,

| |  ...at least in your opinion <g>
| 
| And since my opinions are excellent...

 ...examples of my personal biases.  <gd&r>

-- 

   Q  --  XanaNews 1.19.1.372 -  2015-07-30 11:01:18
0
Quentin
7/30/2015 6:02:11 PM
Quentin Correll wrote:

> Rudy,
> 
> | |  ...at least in your opinion <g>
> >  
> >  And since my opinions are excellent...
> 
>  ...examples of my personal biases.  <gd&r>

Of your personal biases? Nah, I don't think so.

-- 
Rudy Velthuis        http://www.rvelthuis.de

"The Pope!?! How many divisions has he got?"
 -- Joseph Stalin
0
Rudy
7/31/2015 6:52:19 AM
Rudy,

| > | |  ...at least in your opinion <g>
| |  >  
| |  >  And since my opinions are excellent...
| |  
| |   ...examples of my personal biases.  <gd&r>
| 
| Of your personal biases? Nah, I don't think so.

"my" = Rudy's 


-- 

   Q  --  XanaNews 1.19.1.372 -  2015-07-31 15:28:47
0
Quentin
8/1/2015 10:09:01 PM
Quentin Correll wrote:

> Rudy,
> 
> | > | |  ...at least in your opinion <g>
> | |  >  
> | |  >  And since my opinions are excellent...
> >  |  
> | |   ...examples of my personal biases.  <gd&r>
> >  
> >  Of your personal biases? Nah, I don't think so.
> 
> "my" = Rudy's 

Er, I am Rudy. I'm quite sure. I just asked my wife, and she confirms
it.

-- 
Rudy Velthuis        http://www.rvelthuis.de

"Men have become the tools of their tools."
 -- Henry David Thoreau (1817-1862)
0
Rudy
8/1/2015 11:38:35 PM
Rudy Velthuis (TeamB) wrote:

> Quentin Correll wrote:
> 
> > Rudy,
> > 
> > | > | |  ...at least in your opinion <g>
> > | |  >  
> > | |  >  And since my opinions are excellent...
> > >  |  
> > | |   ...examples of my personal biases.  <gd&r>
> > >  
> > >  Of your personal biases? Nah, I don't think so.
> > 
> > "my" = Rudy's 
> 
> Er, I am Rudy. I'm quite sure. I just asked my wife, and she confirms
> it.

Yes, he is Rudy. I confirm it.

-- 
Rudy Velthuis' wife
0
Rudy
8/2/2015 8:17:53 AM
Rudy,

| Yes, he is Rudy. I confirm it.
| 
| -- 
| Rudy Velthuis' wife

<giggle>

-- 

   Q  --  XanaNews 1.19.1.372 -  2015-08-02 10:27:34
0
Quentin
8/2/2015 5:27:44 PM
Reply:

Similar Artilces:

Delphi Generics... and bloat.
I've been playing with and introducing generics more and more lately, and if they undoubtably provide the best language enhancement since interfaces were introduced to Delphi, but... /rant on ....I've been a bit annoyed by the bloat present in the basic collections... on one side, if all the basic containers are there, on the other side, there isn't an insane choice, and they're IMO all trying to too hard to be too generic, and lack specialization. F.i. they all implement enumerators and/or have virtual methods (which can't be optimized away by the compil...

MOVED: Delphi Generics... and bloat.
Thread moved to embarcadero.public.delphi.rtl -- Rudy Velthuis (TeamB) http://www.teamb.com "Now, now my good man, this is no time for making enemies." -- Voltaire (1694-1778) on his deathbed in response to a priest asking that he renounce Satan. ...

Fighting Delphi generics code bloat
Hi all, I have submitted new QC TObjectList<T: class> is not optimaly implemented and leads to code bloat http://qc.embarcadero.com/wc/qcmain.aspx?d=108966 But I have the feeling I will need community support to make Embarcadero realize the problem. Basically, TObjectList<T> inherits from TList<T> and that leads to coping the whole TList<T> code every time you use TObjectList<T> for specific class. It would be much better if TObjectList<T> would inherit from old TObjectList that can handle object lists from single code base. Dalija Pras...

Are Delphi Win32 generics Generics at all? [Edit]
It is more like template, not generics. Try this TForm3 = class(TForm) ...... function Violate < T:Tcontrol> :T; end; function TForm3.Violate < T > : T; begin result:=self //It is not type safe. No Errors from compiler(but generics are type checked in empty type environment with no binding to actual type params) end; Compiler defers type checking for instantiation time. add line Violate < TGraphicControl > ; < - //The compiler informs you about an error. But as in C++ templates you dont know where the actu...

here's a tech question for non-tech
I have not had occasion to want to do this before, so I'm hoping someone can enlighten me. I have an app built in D7, and it's rather complex in its functionality. Is it possible to rebuild the app to run as a service? Would that require separating the user interface from the app? Thanks, Bill William Meyer wrote on 4/22/2010 : > I have not had occasion to want to do this before, so I'm hoping > someone can enlighten me. I have an app built in D7, and it's rather > complex in its functionality. Is it possible to rebuild the app to run > as a service?...

Delphi Generics
How does Delphi 2009+'s implementation of generics compare to other strongly typed languages? What are the advantages/disadvantages of Delphi's implementation? For instance C++ uses the notion class and function templates as well as template specialization, which is very powerful but has been criticized for creating code bloat because a unique type is created when a template is resolved. Java's implementation uses type erasure but this makes it difficult to determine the type at runtime. So how does Delphi's generics work under the hood? Kenneth Cochran wrote: > H...

Going from generic html.Form() to non-generic html.BeginForm()
Hi I have just upgraded to the ASP.NET MVC Beta (from one of the previews) where the Html.Form()-method now has been replaced by the Html.BeginForm() (and EndForm) and at the same time it has gone from generic to non-generic. Does anybody have a suggestion for what the best way will be to rewrite the following code to the new version? Here is a code example where the Authenticate-method return an ActionResult:<% using (Html.Form<AuthenticationController>(c => c.Authenticate())) { %> The layout for the login form<%} %> See http://forums.asp.net/t...

Generics and instantiation
Is there a way to instantiate an object based on a generic type? I know there's a "constructor" constraint, but as far as I could see it only let me call a no-arg 'Create' constructor, is it correct? Is there a way to call other constructors? I've tried this: program Project2; {$APPTYPE CONSOLE} uses SysUtils; type TBase = class private FParam: Integer; public constructor Create(Param: Integer); property Param: Integer read FParam; end; TBaseClass = class of TBase; TSubClassA = class(TBase) end; TTest&l...

Going from generic html.Form() to non-generic html.BeginForm()
Hi I have just upgraded to the ASP.NET MVC Beta (from one of the previews) where the Html.Form()-method now has been replaced by the Html.BeginForm() (and EndForm) and at the same time it has gone from generic to non-generic. Does anybody have a suggestion for what the best way will be to rewrite the following code to the new version? Here is a code example where the Authenticate-method return an ActionResult:<% using (Html.Form<AuthenticationController>(c => c.Authenticate())) { %> The layout for the login form<%} %>   Hi The BeginForm<...

How to Prevent the same Stored Procedure from executing at the same time on multiple threads (multiple apps).
We have an issue here where I work. We have a DB table with a pool of available values (10 digit numbers). Our applications will call this stored procedure when it needs a new number. We retrieve it, then flag the record as used. The problem we are running into is that every so often we have two threads (two applications) that are requesting a number at the same time. Somehow two applications are receiving the same number. The first application receives the number, and then the second application is receiving the same number before the first one has flagged it as used. The q...

Upgrade from Delphi 5 and Delphi XE: Variant and SysUtils unit problems.
Hi. I am a newbie to Delhi XE. I have just taken on the task of converting my stuff from Delphi 5 [sic] to Delphi XE. The first errors I got was "Variants unit out of data or corrupted" and "symbol deprecated" in SysUtils I hope I can fix the problem by simply pointing to the "up-to-date" units. I am also wondering wether I will not have to switch to Unicode, since the errors seem to be string related (not that I know what changing to Unicode entails). Any help? Marcus > {quote:title=Marcus de Bruin wrote:}{quote} > Hi. > > I...

Models?? unit testing examples needed for TDD (agile, eXtreme Programming), also for non TDD unit tests ...
Since the Model is the ultimate commander of the View, andsince the Controller is the messenger servant of the Model,it seems appropriate in the TDD paradigm that one shouldbegin by writing her/his first failing code for the Model.  example:  something like        public sometype wellnamedmethod()        {            throw new NotImplementedException("implementation deferred!");        }    ...

Generics and code bloat?
In Marco's 2009 Handbook he states: "Similarly, the same instance of a generic type used in different units forces the compiler to generate the same code over and over, possibly causing significant code bloat." If I do this: unit1; type TMyList = class(TList<TForm>) end; TForm1 = class(TForm) private { Private declarations } public { Public declarations } FList: TMyList; end; **************************** unit2; uses Unit1; type TNewForm1 = class(TForm) private { Private declarations } public { P...

Non execution of TSaveDialog
Hi, This is a follow up to my last question about TSaveDialog. For a few of my users, when the application calls the TSaveDialog Execute method nothing happens. I had originally thought that this was linked to Vista, but I have now discovered that was a red herring and the problem can occur on Windows XP as well. I am using Borland C++ Builder 6. I cannot get any more error information from the call to the TSaveDialog Execute method because I am unable to supply my user with a new version of software purely to investigate this problem, thus I am trying to debug it without being able to...

Web resources about - Do generic instantiations in multiple units bloat the executable? - embarcadero.delphi.non-tech

Instantiation - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...


Java Tip 67: Lazy instantiation
The balance between the performance of software and the resources it consumes has been an issue since the birth of computers. It stems from the ...

Google Releases Recently-Acquired Instantiations Development Tools, Free Of Charge
Back in August Google acquired Instantiations, the developer of a suite of popular development tools focused on Google's Google Web Toolkit, ...

Thomas Aquinas - Wikipedia, the free encyclopedia
Giles of Rome , Godfrey of Fontaines , Hooker , Locke , Dante , Leibniz , Martain , Gilson , Anscombe , Donoso Cortés , Eckhart , Chesterton ...

Presentations ~ Stephen's Web
Stephen's Web, the home page of Stephen Downes, with news and information on e-learning, new media, instructional technology, educational design, ...

The Journal of Religion and Popular Culture
The Journal of Religion and Popular Culture is committed to the academic exploration, analysis and interpretation, from a variety of disciplinary ...

Dictionary of Philosophy of Mind - functionalism
functionalism(1) - The view that the physical realization of a functional component is not, in some sense, its essence. Rather, what makes a ...

The Future of Journalism
Openbusiness has interviewed Kenneth Neil Cukier, who is a technology correspondent for The Economist in London specialising in public policy ...

RICHARD CHARTIER - BIO
Listening to Richard Chartier’s work is like sitting in a room at dusk while the light fades. As colours and detail drain away the eye seeks ...

Resources last updated: 11/24/2015 11:11:30 PM