digitalmars.D.announce - A New Import Idiom`
- Mike Parker (8/8) Feb 13 2017 Daniel Nielsen put together a post describing the import idiom
- jmh530 (5/13) Feb 13 2017 A great post.
- Daniel N (4/18) Feb 13 2017 Probably, please help measuring your idea and post it here. I
- jmh530 (15/19) Feb 13 2017 The first time I did it, I got a ~60% decline in compilation
- Daniel N (2/11) Feb 13 2017 Cool, thanks for checking!
- Johan Engelen (53/63) Feb 13 2017 In case you don't actually use the function, things are faster
- Daniel Nielsen (7/11) Feb 13 2017 You're disqualified for using LDC, it's too good. ;) Just
- Johan Engelen (7/10) Feb 13 2017 Why would you expect there to be a difference?
- Daniel Nielsen (3/14) Feb 13 2017 Sorry, I misread your post. In Jack Stouffer test, main() was
- Bastiaan Veelo (2/4) Feb 13 2017 An entertaining read!
- Johan Engelen (5/7) Feb 13 2017 I also liked the post, nicely written.
- =?UTF-8?Q?Ali_=c3=87ehreli?= (6/7) Feb 13 2017 I claimed there is a performance improvement in compilation. Can someone...
- Jerry (10/16) Feb 13 2017 I ran it a couple of times and just doing the following has a
- Daniel N (26/47) Feb 13 2017 I suspect you test something slightly different, I tested both on
- kinke (2/5) Feb 14 2017 Yes. +1
- Dmitry Olshansky (5/8) Feb 14 2017 +1
- Jonathan M Davis via Digitalmars-d-announce (9/15) Feb 14 2017 Honestly, as hideous as functions signatures can get - particularly with
- Arun Chandrasekaran (8/18) Feb 14 2017 Honestly, after staring at C++ STL, I never imaged that the
- Dominikus Dittes Scherkl (3/11) Feb 14 2017 Thanks for writing this up, Daniel. Has become quite a nice
Daniel Nielsen put together a post describing the import idiom that came to light in a recent forum discussion regarding DIP 1005 [3]. The relevant links are at [1] and [2]. [1] https://dlang.org/blog/2017/02/13/a-new-import-idiom/ [2] https://www.reddit.com/r/programming/comments/5tt33y/a_new_import_idiom_for_d/ [3] https://forum.dlang.org/thread/tzqzmqhankrkbrfsrmbo forum.dlang.org?page=1
Feb 13 2017
On Monday, 13 February 2017 at 14:28:20 UTC, Mike Parker wrote:Daniel Nielsen put together a post describing the import idiom that came to light in a recent forum discussion regarding DIP 1005 [3]. The relevant links are at [1] and [2]. [1] https://dlang.org/blog/2017/02/13/a-new-import-idiom/ [2] https://www.reddit.com/r/programming/comments/5tt33y/a_new_import_idiom_for_d/ [3] https://forum.dlang.org/thread/tzqzmqhankrkbrfsrmbo forum.dlang.org?page=1A great post. With the Jack Stouffer comparison, wouldn't it be fairer to do: import std.datetime : Systime; import std.traits : isIntegral;
Feb 13 2017
On Monday, 13 February 2017 at 15:00:24 UTC, jmh530 wrote:On Monday, 13 February 2017 at 14:28:20 UTC, Mike Parker wrote:Probably, please help measuring your idea and post it here. I intentionally chose a test made by someone else to avoid biasing from my part. It was the only test I found at time of writing.Daniel Nielsen put together a post describing the import idiom that came to light in a recent forum discussion regarding DIP 1005 [3]. The relevant links are at [1] and [2]. [1] https://dlang.org/blog/2017/02/13/a-new-import-idiom/ [2] https://www.reddit.com/r/programming/comments/5tt33y/a_new_import_idiom_for_d/ [3] https://forum.dlang.org/thread/tzqzmqhankrkbrfsrmbo forum.dlang.org?page=1A great post. With the Jack Stouffer comparison, wouldn't it be fairer to do: import std.datetime : Systime; import std.traits : isIntegral;
Feb 13 2017
On Monday, 13 February 2017 at 15:04:53 UTC, Daniel N wrote:Probably, please help measuring your idea and post it here. I intentionally chose a test made by someone else to avoid biasing from my part. It was the only test I found at time of writing.The first time I did it, I got a ~60% decline in compilation speed and binary size. I called dmd without any extra settings after making the above change (and adding a main function). It seemed weird that it's even better than in his comparison. Maybe he had used some settings I hadn't. So I tried it again comparing all three versions on my machine. This time I didn't notice a difference in compilation speed or binary size between the version with import std.datetime; import std.traits; and the one with import std.datetime : SysTime; import std.traits : isIntegral; So I'm not sure it matters.
Feb 13 2017
On Monday, 13 February 2017 at 16:17:49 UTC, jmh530 wrote:So I tried it again comparing all three versions on my machine. This time I didn't notice a difference in compilation speed or binary size between the version with import std.datetime; import std.traits; and the one with import std.datetime : SysTime; import std.traits : isIntegral; So I'm not sure it matters.Cool, thanks for checking!
Feb 13 2017
On Monday, 13 February 2017 at 15:04:53 UTC, Daniel N wrote:On Monday, 13 February 2017 at 15:00:24 UTC, jmh530 wrote:In case you don't actually use the function, things are faster and you get a smaller object file because the template is never instantiated. So if the function is never used in the module (it is just there for other modules to use), then things are indeed faster and smaller. But you also don't get compile checking on it; putting only ``` void func(T)(from!"std.datetime".SysTime a, T value) if (from!"std.traits".isIntegral!T) { import std.stdio : writeln; writeln(a, value); } ``` in a file compiles fast without complaints about an undefined `from`. But for a full program, compile time is the same (it's really short so you can't really conclude much from it), and binary size as well (LDC 1.1.0, -O3). For my test cases below, the binaries are identical, except for around 30 bytes... My test cases: ``` template from(string moduleName) { mixin("import from = " ~ moduleName ~ ";"); } void func(T)(from!"std.datetime".SysTime a, T value) if (from!"std.traits".isIntegral!T) { import std.stdio : writeln; writeln(a, value); } void main() { func!int(from!"std.datetime".SysTime(), 1); } ``` ``` import std.datetime; import std.traits; void func(T)(SysTime a, T value) if (isIntegral!T) { import std.stdio : writeln; writeln(a, value); } void main() { import std.datetime : SysTime; func!int(SysTime(), 1); } ``` -JohanWith the Jack Stouffer comparison, wouldn't it be fairer to do: import std.datetime : Systime; import std.traits : isIntegral;Probably, please help measuring your idea and post it here. I intentionally chose a test made by someone else to avoid biasing from my part. It was the only test I found at time of writing.
Feb 13 2017
On Monday, 13 February 2017 at 19:41:11 UTC, Johan Engelen wrote:But for a full program, compile time is the same (it's really short so you can't really conclude much from it), and binary size as well (LDC 1.1.0, -O3). For my test cases below, the binaries are identical, except for around 30 bytes...You're disqualified for using LDC, it's too good. ;) Just kidding, well I did see it coming so I safeguarded with linker section. I still suspect there will be a difference in real-world applications even with LDC. Glad you liked it. Daniel
Feb 13 2017
On Monday, 13 February 2017 at 20:09:45 UTC, Daniel Nielsen wrote:I still suspect there will be a difference in real-world applications even with LDC.Why would you expect there to be a difference? Module ctors/dtors are still pulled in, regardless of the import being selective or not. What am I missing? Thanks, Johan
Feb 13 2017
On Monday, 13 February 2017 at 21:04:05 UTC, Johan Engelen wrote:On Monday, 13 February 2017 at 20:09:45 UTC, Daniel Nielsen wrote:Sorry, I misread your post. In Jack Stouffer test, main() was empty!I still suspect there will be a difference in real-world applications even with LDC.Why would you expect there to be a difference? Module ctors/dtors are still pulled in, regardless of the import being selective or not. What am I missing? Thanks, Johan
Feb 13 2017
On Monday, 13 February 2017 at 14:28:20 UTC, Mike Parker wrote:Daniel Nielsen put together a post [1] https://dlang.org/blog/2017/02/13/a-new-import-idiom/An entertaining read!
Feb 13 2017
On Monday, 13 February 2017 at 14:28:20 UTC, Mike Parker wrote:Daniel Nielsen put together a post ... [1] https://dlang.org/blog/2017/02/13/a-new-import-idiom/I also liked the post, nicely written. I didn't check, but if this idiom is not already tested in dmd-testsuite, please add it! -Johan
Feb 13 2017
On 02/13/2017 06:28 AM, Mike Parker wrote:https://www.reddit.com/r/programming/comments/5tt33y/a_new_import_idiom_for_d/I claimed there is a performance improvement in compilation. Can someone answer kibwen's question on this subthread please: https://www.reddit.com/r/programming/comments/5tt33y/a_new_import_idiom_for_d/ddp6a4p/ Ali
Feb 13 2017
On Monday, 13 February 2017 at 22:40:55 UTC, Ali Çehreli wrote:On 02/13/2017 06:28 AM, Mike Parker wrote:I ran it a couple of times and just doing the following has a faster compile time: import std.datetime : SysTime; import std.traits : isIntegral; No difference in binary size as the article stated either, using dmd. Anyways yes this is kind of cool and fascinating how it works, but that aside I hope I never see this used in phobos. Does anyone else feel this way?https://www.reddit.com/r/programming/comments/5tt33y/a_new_import_idiom_for_d/I claimed there is a performance improvement in compilation. Can someone answer kibwen's question on this subthread please: https://www.reddit.com/r/programming/comments/5tt33y/a_new_import_idiom_for_d/ddp6a4p/ Ali
Feb 13 2017
On Tuesday, 14 February 2017 at 02:32:33 UTC, Jerry wrote:On Monday, 13 February 2017 at 22:40:55 UTC, Ali Çehreli wrote:I suspect you test something slightly different, I tested both on linux and windows, with dmd, ldc and gdc(not on windows). time dmd slow.d time dmd fast.d ====== Slow ====== import std.datetime : SysTime; import std.traits : isIntegral; void func(T)(SysTime a, T value) if (isIntegral!T) { import std.stdio : writeln; writeln(a, value); } void main() {} ====== Fast ====== template from(string moduleName) { mixin("import from = " ~ moduleName ~ ";"); } void func(T)(from!"std.datetime".SysTime a, T value) if (from!"std.traits".isIntegral!T) { import std.stdio : writeln; writeln(a, value); } void main() {}On 02/13/2017 06:28 AM, Mike Parker wrote:I ran it a couple of times and just doing the following has a faster compile time: import std.datetime : SysTime; import std.traits : isIntegral; No difference in binary size as the article stated either, using dmd. Anyways yes this is kind of cool and fascinating how it works, but that aside I hope I never see this used in phobos. Does anyone else feel this way?https://www.reddit.com/r/programming/comments/5tt33y/a_new_import_idiom_for_d/I claimed there is a performance improvement in compilation. Can someone answer kibwen's question on this subthread please: https://www.reddit.com/r/programming/comments/5tt33y/a_new_import_idiom_for_d/ddp6a4p/ Ali
Feb 13 2017
On Tuesday, 14 February 2017 at 02:32:33 UTC, Jerry wrote:Anyways yes this is kind of cool and fascinating how it works, but that aside I hope I never see this used in phobos. Does anyone else feel this way?Yes. +1
Feb 14 2017
On 2/14/17 3:32 AM, Jerry wrote:Anyways yes this is kind of cool and fascinating how it works, but that aside I hope I never see this used in phobos. Does anyone else feel this way?+1 Let's not make Phobos as scary as C++ STL. --- Dmitry Olshansky
Feb 14 2017
On Wednesday, February 15, 2017 00:01:42 Dmitry Olshansky via Digitalmars-d- announce wrote:On 2/14/17 3:32 AM, Jerry wrote:Honestly, as hideous as functions signatures can get - particularly with heavily templated stuff, I think that the result tends to be far more understandable than the likes of the STL of Boost. That being said, I think that D function signaures are certainly pushing it as it is, and I don't think that the benefits of adding imports to them is worth the clutter that they add. - Jonathan M DavisAnyways yes this is kind of cool and fascinating how it works, but that aside I hope I never see this used in phobos. Does anyone else feel this way?+1 Let's not make Phobos as scary as C++ STL.
Feb 14 2017
On Tuesday, 14 February 2017 at 23:01:42 UTC, Dmitry Olshansky wrote:On 2/14/17 3:32 AM, Jerry wrote:Honestly, after staring at C++ STL, I never imaged that the standard library of a language can be *readable* and *understandable* until I read phobos. Kudos to Walter, Andrei and contributors. I still believe that templated D code is much more readable and intuitive than templated C++ code. ArunAnyways yes this is kind of cool and fascinating how it works, but that aside I hope I never see this used in phobos. Does anyone else feel this way?+1 Let's not make Phobos as scary as C++ STL. --- Dmitry Olshansky
Feb 14 2017
On Monday, 13 February 2017 at 14:28:20 UTC, Mike Parker wrote:Daniel Nielsen put together a post describing the import idiom that came to light in a recent forum discussion regarding DIP 1005 [3]. The relevant links are at [1] and [2]. [1] https://dlang.org/blog/2017/02/13/a-new-import-idiom/ [2] https://www.reddit.com/r/programming/comments/5tt33y/a_new_import_idiom_for_d/ [3] https://forum.dlang.org/thread/tzqzmqhankrkbrfsrmbo forum.dlang.org?page=1Thanks for writing this up, Daniel. Has become quite a nice article.
Feb 14 2017