Help optimize D solution to phone encoding problem: extremely slow performace.

evilrat evilrat666 at gmail.com
Wed Jan 17 09:20:46 UTC 2024


On Wednesday, 17 January 2024 at 07:06:25 UTC, Renato wrote:
> On Tuesday, 16 January 2024 at 22:15:04 UTC, Siarhei Siamashka 
> wrote:
>> On Tuesday, 16 January 2024 at 21:15:19 UTC, Renato wrote:
>>
>> It's a GC allocations fest. Things like this make it slow:
>>
>> ```diff
>>      {
>> -        string digit = [digits[0]];
>> +        string digit = digits[0 .. 1];
>>          words.insertBack(digit);
>> ```
>
> I was under the impression that `[digits[0]]` would just use a 
> stack allocation??
>
> The profiler does not show any GC anymore, are you sure it's a 
> "GC allocations fest"???
>

nah, you are allocating new array out of single digit while the 
latter is just takes a slice.

there is 'scope' storage specifier for when you know your 
variable won't escape the scope to place it on stack (works for 
classes too), but I'm not sure if it will work with array.

`scope string digit = [digits[0]];`


More information about the Digitalmars-d-learn mailing list