These are chat archives for boostorg/hana

1st
Mar 2016
Maik Klein
@MaikKlein
Mar 01 2016 01:45
Not sure if you find this interesting but I "sort of" showcased the idea of hana in D https://www.reddit.com/r/programming/comments/48dssq/metaprogramming_with_type_objects_in_d/
Louis Dionne
@ldionne
Mar 01 2016 13:28
@MaikKlein Thanks for the heads up, I’ll have a look!
Louis Dionne
@ldionne
Mar 01 2016 13:49
Screen Shot 2016-03-01 at 08.48.40.png
@ricejasonf This is a benchmark of hana::make_map before and after the optimization I talked about yesterday. I’ll push the changes now.
Louis Dionne
@ldionne
Mar 01 2016 13:59
@MaikKlein Cool article! I’m a D illiterate, but I see the idea. Did you measure the compile-times of these metafunctions? Is D doing much better than C++?
Maik Klein
@MaikKlein
Mar 01 2016 16:59
@ldionne D is much much faster than C++ for compile time stuff. I could create a few benchmarks maybe later today so that we have some "hard data".
It shouldn't be too hard to create them because you can actually build strings at compile time and compile them at compile time.
I'll let you know when I have something.
Jason Rice
@ricejasonf
Mar 01 2016 17:03
:+1:
@ldionne That is a dramatic improvement!
Maik Klein
@MaikKlein
Mar 01 2016 17:18
I'll try to stay as close to the benchmarks of hana as possible.
Jason Rice
@ricejasonf
Mar 01 2016 17:20
It might be possible to put it in there if we can make a custom target to compile the D version with cmake.
@ldionne Do you know if clang c++1z supports constexpr lambdas? I saw this https://groups.google.com/a/isocpp.org/forum/#!msg/std-proposals/WllUuPBDyxQ/_EF8Ppvh_vQJ
Maik Klein
@MaikKlein
Mar 01 2016 17:33
Super rough test, but I replicated https://github.com/boostorg/hana/blob/master/benchmark/filter/compile.hana.tuple.erb.cpp I also do a bit more work at compile time. I build the string and compile to a AliasSeq at compile time and then I filter it. I filter a tuple of 10k integers with isEven. Everything takes 3.7 seconds to compile.
and with 1000 integers it completes in 0.5 seconds.
I am scared to try to compile 100k integers :D
Maik Klein
@MaikKlein
Mar 01 2016 17:38
okay I run out of memory
dmd failed with exit code -9. This may indicate that the process has run out of memory.
dub build  4.96s user 4.16s system 35% cpu 25.502 total
Jason Rice
@ricejasonf
Mar 01 2016 17:39
What is the 'string' that you are building?
Maik Klein
@MaikKlein
Mar 01 2016 17:42
enum types = "AliasSeq!(" ~ iota(0,100000).map!(i => to!string(i)).join(",") ~ ")";
You can basically just use any runtime function at compile time in D
so I just create a list of "1,2,3,4,5,6,7,8,...."
and create a new type tuple based of it AliasSeq!(1,2,3,4,5,6,7,8,....)
do you want to test it yourself?
Jason Rice
@ricejasonf
Mar 01 2016 17:47
oh lol.. so kind of like what the eruby stuff is doing
it looks the same too
Maik Klein
@MaikKlein
Mar 01 2016 17:47
yeah just with the time that eruby takes
btw how far can you go in hana?
on your machine? for filter for example
for me in D it is somewhere between 10k and 100k that I run out of memory
Jason Rice
@ricejasonf
Mar 01 2016 17:53
It would probably take a long time to get to 10k if it could :P
but hana:tuple would have to store each value wrapped in an integral_constant
I think we would have to make something like hana::experimental::types for integrals for it to be a fair comparison
Maik Klein
@MaikKlein
Mar 01 2016 17:57
I can filter a type tuple of size 1000 a 100times and it takes 0.65seconds.
Jason Rice
@ricejasonf
Mar 01 2016 17:58
what is the filter predicate?
Maik Klein
@MaikKlein
Mar 01 2016 17:58
enum isEven(alias i) = i % 2 is 0;
Jason Rice
@ricejasonf
Mar 01 2016 17:58
are you saying that i is a type?
Maik Klein
@MaikKlein
Mar 01 2016 17:59
no it just needs to support the modulo operator
in this case its a type tuple with ulongs
so kinda big
nvm
it is also of type int
Maik Klein
@MaikKlein
Mar 01 2016 18:14
okay it seemed to cache the type instantiations, so I mixed it up filtering 100 times a 1000 element list with isEven takes 10 seconds.
it still fails if I try to filter a 10k list 10 times
Maik Klein
@MaikKlein
Mar 01 2016 18:22
filtering 20 times a 1000 element list takes 20 seconds. I'll do "real" benchmarks later.
Unfortunately with libstdc++ it blows up at 256 recursive template instantiations inside std::make_index_sequence (I think)
that filter function is optimized for integrals (I think :grin: )
so it should be more "apples to apples" for your comparison
Jason Rice
@ricejasonf
Mar 01 2016 20:28
So, on my intel-nuc it takes .17s for 250. 250 on my macbook air takes .27s. 10k on my air takes .8s
6.1s with 100k
Jason Rice
@ricejasonf
Mar 01 2016 20:38
1M explodes with a message about a possible infinite loop at 46s :laughing:
500k isn't much better
Jason Rice
@ricejasonf
Mar 01 2016 20:45
So D doesn't look like a panacea for metaprogramming, but that static if thing looks like it could save some headaches.
Jason Rice
@ricejasonf
Mar 01 2016 21:59
I heard they are trying to get something like if constexpr(x) in C++17.