Thread overview | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 21, 2015 Object.factory() and exe file size bloat | ||||
---|---|---|---|---|
| ||||
This function: http://dlang.org/phobos/object.html#.Object.factory enables a program to instantiate any class defined in the program. To make it work, though, every class in the program has to have a TypeInfo generated for it. This leads to bloat: https://issues.dlang.org/show_bug.cgi?id=14758 and sometimes the bloat can be overwhelming. The solution seems straightforward - only have Object.factory be able to instantiate classes marked as 'export'. This only makes sense anyway. What do you think? |
August 21, 2015 Re: Object.factory() and exe file size bloat | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On 21-Aug-2015 08:06, Walter Bright wrote: > This function: > > http://dlang.org/phobos/object.html#.Object.factory > > enables a program to instantiate any class defined in the program. To > make it work, though, every class in the program has to have a TypeInfo > generated for it. This leads to bloat: > > https://issues.dlang.org/show_bug.cgi?id=14758 > > and sometimes the bloat can be overwhelming. > > The solution seems straightforward - only have Object.factory be able to > instantiate classes marked as 'export'. This only makes sense anyway. > > What do you think? +1000 Though I'd kill the whole object factory if I had a chance. It looks a lot like Java-woannabe feature that may be better done with UDA's and meta-programming (like e.g. run--time type info can be based on compile-time one). -- Dmitry Olshansky |
August 21, 2015 Re: Object.factory() and exe file size bloat | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Friday, 21 August 2015 at 05:06:47 UTC, Walter Bright wrote:
> This function:
>
> http://dlang.org/phobos/object.html#.Object.factory
>
> enables a program to instantiate any class defined in the program. To make it work, though, every class in the program has to have a TypeInfo generated for it. This leads to bloat:
>
> https://issues.dlang.org/show_bug.cgi?id=14758
>
> and sometimes the bloat can be overwhelming.
>
> The solution seems straightforward - only have Object.factory be able to instantiate classes marked as 'export'. This only makes sense anyway.
>
> What do you think?
Wait ? Why only classes marked export ? I don't follow the reasoning here.
|
August 21, 2015 Re: Object.factory() and exe file size bloat | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Friday, 21 August 2015 at 05:06:47 UTC, Walter Bright wrote:
> This function:
>
> http://dlang.org/phobos/object.html#.Object.factory
>
> enables a program to instantiate any class defined in the program. To make it work, though, every class in the program has to have a TypeInfo generated for it:
>
> [...]
>
> What do you think?
This is a good idea. Some other langs use a similar system with a registration.
Eg instances can only be streamed if type is registered.
Other alternatives would be a pragma or an attribute to disable TypeInfo generation.
@NoTI.
|
August 21, 2015 Re: Object.factory() and exe file size bloat | ||||
---|---|---|---|---|
| ||||
Posted in reply to deadalnix | On Fri, Aug 21, 2015 at 05:15:00AM +0000, deadalnix via Digitalmars-d wrote: > On Friday, 21 August 2015 at 05:06:47 UTC, Walter Bright wrote: > >This function: > > > > http://dlang.org/phobos/object.html#.Object.factory > > > >enables a program to instantiate any class defined in the program. To make it work, though, every class in the program has to have a TypeInfo generated for it. This leads to bloat: > > > > https://issues.dlang.org/show_bug.cgi?id=14758 > > > >and sometimes the bloat can be overwhelming. > > > >The solution seems straightforward - only have Object.factory be able to instantiate classes marked as 'export'. This only makes sense anyway. > > > >What do you think? > > Wait ? Why only classes marked export ? I don't follow the reasoning here. Because if your code imports the module that defines the class, you already know the class name (either by design, or by compile-time introspection) so you don't need to use the object factory. It's only when you want to dynamically load new classes at runtime that you didn't know about at compile-time, that you need to use the object factory -- and that's also when you'd mark classes as 'export'. Makes sense to me. T -- Windows: the ultimate triumph of marketing over technology. -- Adrian von Bidder |
August 21, 2015 Re: Object.factory() and exe file size bloat | ||||
---|---|---|---|---|
| ||||
Posted in reply to BBasile | On 8/20/2015 10:24 PM, BBasile wrote:
> Other alternatives would be a pragma or an attribute to disable TypeInfo
> generation.
Interestingly, my idea would not disable TypeInfo generation. Instead, the TypeInfo would be generated into a COMDAT section. Then, only if it is referenced is it linked in.
The ModuleInfo, as it currently is implemented, contains a reference to every class TypeInfo, thus pulling them all in.
|
August 21, 2015 Re: Object.factory() and exe file size bloat | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Friday, 21 August 2015 at 05:35:21 UTC, Walter Bright wrote: > On 8/20/2015 10:24 PM, BBasile wrote: >> Other alternatives would be a pragma or an attribute to disable TypeInfo >> generation. > > Interestingly, my idea would not disable TypeInfo generation. Instead, the TypeInfo would be generated into a COMDAT section. Then, only if it is referenced is it linked in. Disabling TypeInfo forces one to compromise on slicing, postblit, and potentially others useful features, so finding a way to keep TypeInfo, yet remove the dead code is much less of a blunt instrument, and very much preferred. > The ModuleInfo, as it currently is implemented, contains a reference to every class TypeInfo, thus pulling them all in. Ideally it would be nice to only pull in those ModuleInfo instances that are actually needed in the program, and by association, only pull in those TypeInfo instances needed by the ModuleInfo. If no ModuleInfo is used, and the associated TypeInfo is also not used, then neither is pulled in. Mike |
August 21, 2015 Re: Object.factory() and exe file size bloat | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On Friday, 21 August 2015 at 05:06:47 UTC, Walter Bright wrote:
> This function:
>
> http://dlang.org/phobos/object.html#.Object.factory
>
> enables a program to instantiate any class defined in the program. To make it work, though, every class in the program has to have a TypeInfo generated for it. This leads to bloat:
>
> https://issues.dlang.org/show_bug.cgi?id=14758
>
> and sometimes the bloat can be overwhelming.
>
> The solution seems straightforward - only have Object.factory be able to instantiate classes marked as 'export'. This only makes sense anyway.
>
> What do you think?
+1000!
|
August 21, 2015 Re: Object.factory() and exe file size bloat | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike | On 8/20/2015 11:00 PM, Mike wrote:
> Ideally it would be nice to only pull in those ModuleInfo instances that are
> actually needed in the program, and by association, only pull in those TypeInfo
> instances needed by the ModuleInfo. If no ModuleInfo is used, and the
> associated TypeInfo is also not used, then neither is pulled in.
I do plan to do a review of ModuleInfo with this in mind, but not immediately.
|
August 21, 2015 Re: Object.factory() and exe file size bloat | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter Bright | On 8/21/2015 5:06 PM, Walter Bright wrote:
> This function:
>
> http://dlang.org/phobos/object.html#.Object.factory
>
> enables a program to instantiate any class defined in the program. To
> make it work, though, every class in the program has to have a TypeInfo
> generated for it. This leads to bloat:
>
> https://issues.dlang.org/show_bug.cgi?id=14758
>
> and sometimes the bloat can be overwhelming.
>
> The solution seems straightforward - only have Object.factory be able to
> instantiate classes marked as 'export'. This only makes sense anyway.
>
> What do you think?
I need to look over my code that I've written for my to be web application server.
But: I'm a little concerned that if there is no alternative we won't be able to seriously be able to have a web application server ala JSP servlet style.
So while export may work, perhaps a slightly different approach. If an interface/class is marked as export, it gets inherited. So an child class/implementation would also be export because a super interface/class was export.
This would make me a lot happier.
|
Copyright © 1999-2021 by the D Language Foundation