🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). This channel is logged for the purpose of keeping a history about its development | evalbot usage: 'm: say 3;' or /msg camelia m: ... | Log inspection is getting closer to beta. If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 25 August 2021.
guifa interesting 06:52
Apparently the most performant way to create an object with numerous attributes is just self.bless: attr-a => foo, attr-b => bar
I have a bunch of classes where .new receives an Array-like bit of data, so I figured all of the hashy stuff involved with named arguments would be a slow down 06:54
passing the array through to BUILD or TWEAK and directly setting the attributes ($!attr-a = @args[0]; $!attr-b = @args[1], …) was about 50% slower than self.bless: attr-a => @args[0], attr-b => @args[1], …) 06:57
nine guifa: we have spent considerable time to optimize object construction, so it's not terribly surprising that it's actually quite fast :) 07:51
elcaro guifa: Yeah, I've found with a couple AoC puzzles. Sometime I'd write a solution using a hash, but when the "keys" are known at compiletime, using a class (where "keys" == method) even an anon class trounced the hash in runtime 09:23
codesections guifa/elcaro: for some (2019) benchmark numbers on object construction, see jnthn's Performance Update talk jnthn.net/papers/2019-perlcon-performance.pdf 10:43
(esp. slides 90+)
Nemokosch > Destructuring (and signature unpacks) 11:04
came across this one 😅
guifa nine: yeah, I knew there had been a lot of work on it, but it was just surprising that the direct assignment was so much slower 14:16
the penalty for direct assignment (via TWEAK, BUILD, or similar) is quite substantial 14:17
gist.github.com/alabamenhu/86ee3f2...2bc4d528be 14:19
^^ designed to roughly mirror how most of the stuff is made in CLDR and the different classes are things I think I've tried in the past / am using now / considered using. 14:23
I've been using method B, so switching to A whenever I can and G when I can't should get me a pretty massive improvement at runtime 14:33
codesections m: my class A {}; say A.^lookup('BUILD'); say A.^lookup('TWEAK'); say A.^lookup('bless') 15:14
camelia (Mu)
(Mu)
bless
codesections ^^^^ guifa_my understanding is that classes always have a .bless method but *don't* have a BUILD/TWEAK unless you give them one. So using BUILD/TWEAK involves an extra method call (not an alternative one) 15:15
and the pre-assignment options (F & G) are declaring extra variables, so I'm not surprised to see a bit of a slowdown there 15:20
codesections (I _am_ a bit surprised to see how slow the dynamic BUILD is. I would have bet on it being slower than BUILD, but a 2.7× difference is a lot 15:25
)
guifa_ codesections yeah, I figured the pre-assignment would be slower, test just shows how much slower 15:55
Optimizations in theory could remove those assignments, I'd think, just didn't know how strong the static optimizer was for that type of stuff 15:58
codesections My understanding is that, right now, there's almost no static optimization – lots of JIT optimization, but not much static. (But I'm hardly an expert) 16:01
guifa_ In any case, this adds one more thing for me to do while I'm cleaning up code in CLDR 16:03
but with the nice side effect of it probably reducing up the load time for language data by nearly 50% 16:04
it's just … so many files to update hahaha (I think it was gfldex that ran the numbers and it's the largest module by LOC in the ecosystem) 16:07
japhb_ guifa_: How do all those compare with *not* overriding new, and just instantiating a class with 12 attributes the "old fashioned way"? 16:39
guifa_ japhb_ : good question. That doesn't work in my case (the .new for CLDR types passes an index and a blob: no type has knowledge of other types are constructed), but I'll try adding it to the test suit 16:42
japhb_ it's basically the same speed, which kind of makes sense. I think the base .new is just method new (|c) { self.bless: |c }, and in both cases they'll be the multi dispatcher's first attempt 16:54
japhb Nod 16:55