Help converting CArray[uint8] to Blob
Hi! Can i get some help in trying to improve the performance of the following snippet? The following code runs inside a react block that it's waiting for channel values. The promise $yenc_promise returns a CStruct with a CArray[uint] $data and a uint8 $data_size. my Instant $init = DateTime.now().Instant; my Data $ed = await $yenc_promise; say "Wating for promise in {DateTime.now.Instant - $init}"; my Instant $init2 = DateTime.now().Instant; my uint8 @data = $ed.data[0..$ed.data_size-1].Array; say "extracting in {DateTime.now.Instant - $init2}"; my Instant $init3 = DateTime.now().Instant; my Blob $bindata = Blob[uint8].new(@data); say "Bindata in {DateTime.now.Instant - $init3}"; say "Total = {DateTime.now.Instant-$init}"; So basically i'm extracting the CArray from the struct and then converting it to a blob (so i can pass it to socket's write function) When i run that code i get the following times: Wating for promise in 0.000409156 extracting in 1.5681954 Bindata in 0.1248611 Total = 1.760531992 How can I improve that piece of code so it will take less than 1 second (against the 1.5 plus secs)? And why if I put more promises running that same code, it gets way slower? For example with five promises: Wating for promise in 0.0003156 Wating for promise in 0.000339 Wating for promise in 0.0003339 Wating for promise in 0.000343 Wating for promise in 0.0003477 extracting in 3.2270008 extracting in 3.4507399 Bindata in 0.4428602 Total = 3.6717681 Bindata in 0.2877211 Total = 3.7541319 extracting in 3.88532646 extracting in 3.72995056 extracting in 3.90478574 Bindata in 0.16822032 Total = 4.0554652 Bindata in 0.15585004 Total = 3.90223033 Best regards, David Santiago
Re: Help converting CArray[uint8] to Blob
On Tue, Jun 16, 2020 at 5:18 PM David Santiago wrote: > my uint8 @data = $ed.data[0..$ed.data_size-1].Array; > my Blob $bindata = Blob[uint8].new(@data); Not absolutely sure, but it seems like you are copying the data twice. Try just my $bindata = Blob.new($ed.data[^$ed.data_size]);
Re: Help converting CArray[uint8] to Blob
Thanks for the answer. There's a slight performance improvement, but It still takes more than 1 second: Code: my Instant $init3 = DateTime.now().Instant; #my Blob $bindata = Blob[uint8].new(@data); my Blob $bindata = Blob[uint8].new($ed.data[^$ed.data_size]); say "Bindata in {DateTime.now.Instant - $init3}"; Bindata in 1.1250962 :-( Curt Tilmes escreveu no dia terça, 16/06/2020 à(s) 21:40: > > On Tue, Jun 16, 2020 at 5:18 PM David Santiago wrote: > > my uint8 @data = $ed.data[0..$ed.data_size-1].Array; > > my Blob $bindata = Blob[uint8].new(@data); > > Not absolutely sure, but it seems like you are copying the data twice. > Try just > > my $bindata = Blob.new($ed.data[^$ed.data_size]);
Re: Help converting CArray[uint8] to Blob
On my MacBook, with Raku 2020.01 built on MoarVM version 2020.01.1 changing: $ed.data[^$ed.data_size] to: $ed.data.head($ed.data_size) cut the time in half. I cannot speak to what might be happening with the Promises. Test code: class Foo { has @.data = 0 xx (1024 ** 2); has $.data_size = @!data.elems; } my Foo $ed .= new; sub time_it ( Int $type ) { for ^3 { my Instant $init3 = DateTime.now().Instant; for ^10 { if $type == 1 { my Blob $bindata = Blob[uint8].new($ed.data[^$ed.data_size]); } else { my Blob $bindata = Blob[uint8].new($ed.data.head($ed.data_size)); } } say "Bindata in {DateTime.now.Instant - $init3}"; } } time_it(1); say ''; time_it(2); Output: Bindata in 8.207297 Bindata in 8.12964 Bindata in 8.0798136 Bindata in 3.434386 Bindata in 3.4062148 Bindata in 3.35743893 — Hope this helps, Bruce Gray (Util of PerlMonks) > On Jun 16, 2020, at 5:17 PM, David Santiago wrote: > > Thanks for the answer. > > There's a slight performance improvement, but It still takes more than 1 > second: > > Code: > > my Instant $init3 = DateTime.now().Instant; > #my Blob $bindata = Blob[uint8].new(@data); > my Blob $bindata = Blob[uint8].new($ed.data[^$ed.data_size]); > say "Bindata in {DateTime.now.Instant - $init3}"; > > > Bindata in 1.1250962 > > > :-( > > Curt Tilmes escreveu no dia terça, 16/06/2020 à(s) 21:40: >> >> On Tue, Jun 16, 2020 at 5:18 PM David Santiago wrote: >>> my uint8 @data = $ed.data[0..$ed.data_size-1].Array; >>> my Blob $bindata = Blob[uint8].new(@data); >> >> Not absolutely sure, but it seems like you are copying the data twice. >> Try just >> >> my $bindata = Blob.new($ed.data[^$ed.data_size]);
Re: Help converting CArray[uint8] to Blob
> my Data $ed = await $yenc_promise; The promise must initialize each element of the CArray[uint]. It looks pretty quick; I'm guessing it's low-level code doing that. > my uint8 @data = $ed.data[0..$ed.data_size-1].Array; > my Blob $bindata = Blob[uint8].new(@data); Afaict that's a total of five HLL element-by-element copies. I would expect this to work and be at least as fast and possibly a lot faster: my Blob $bindata .= new: $ed.data; hth
Interesting W10 and RakudoStar installer error message
Hi All, W10-2004 Pro x 64 RakudoStar-2020.05.1.01-win-x86_64-(JIT).msi I am rolling out Raku on several of my customer's workstations in preperatins to some code I will be installing. Windows 10 takes umbrage to RakudoStar You press "more info" and "run anyway" Huh? Bad dog, bad dog, bad dog! -T