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

Reply via email to