D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 11420 - Inefficient AA value setting
Summary: Inefficient AA value setting
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2013-11-02 05:51 UTC by Kenji Hara
Modified: 2024-12-13 18:13 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Kenji Hara 2013-11-02 05:51:21 UTC
This is both dmd and druntime issue.

By fixing issue 6178, AA value setting with opAssign behavior has been properly fixed in 2.064.

struct S
{
    int val;
    this(int v) { val = 1; }
    void opAssign(S) { val = 2; }
}
void main()
{
    S[int] aa;
    aa[1] = S(1);   // S(1) is moved in the newly allocated AA slot
    aa[1] = S(2);   // opAssign(S1) is called on existing aa[1] value
    assert(aa.length == 1 && aa[1].val == 2);
}

But, the generated code is a little inefficient because it would search the given key twice.

// aa[1] = S(1); is lowered to:
1 in aa ? aa[1].opAssign(S(1)) : aa[1].__ctor(1);
// --> 1 in aa is the first key search.
// --> aa[1]   is the second key search.

To fix the issue, we need to add a new internal function in druntime, and compiler should generate code which uses the function.

The new function's spec is:
- it takes at least two arguments, the AA and assigned value.
- it should return two values, one is the allocated/found slot, and the other is a boolean flag which the returned slot is newly allocated or not.
Comment 1 dlangBugzillaToGithub 2024-12-13 18:13:32 UTC
THIS ISSUE HAS BEEN MOVED TO GITHUB

https://github.com/dlang/dmd/issues/18706

DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB