D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20711 - object.update requires the "update" callback to wastefully return a copy of the updated value
Summary: object.update requires the "update" callback to wastefully return a copy of t...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: druntime (show other issues)
Version: D2
Hardware: All All
: P1 enhancement
Assignee: No Owner
URL:
Keywords: performance, pull
Depends on:
Blocks:
 
Reported: 2020-03-31 05:04 UTC by Vladimir Panteleev
Modified: 2020-03-31 09:29 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 Vladimir Panteleev 2020-03-31 05:04:00 UTC
Here is the current implementation:

https://github.com/dlang/druntime/blob/master/src/object.d#L2670

The line in question is:

        *p = update(*p);

This seems like a wasteful copy to me, and negatively affects AAs with value types which are large or have destructors / postblit constructors. Instead, the update callback can just write to its ref parameter.

I propose to make object.update accept an "update" callback which returns void; in which case, simply omit the first part of the above statement.
Comment 1 Dlang Bot 2020-03-31 05:05:37 UTC
@CyberShadow created dlang/druntime pull request #3012 "Fix Issue 20711 - object.update requires the "update" callback to was…" fixing this issue:

- Fix Issue 20711 - object.update requires the "update" callback to wastefully return a copy of the updated value

https://github.com/dlang/druntime/pull/3012
Comment 2 Dlang Bot 2020-03-31 09:29:44 UTC
dlang/druntime pull request #3012 "Fix Issue 20711 - object.update requires the "update" callback to was…" was merged into master:

- 21c47b36383720ab48625f1a46535eb7da31d7f1 by Vladimir Panteleev:
  Fix Issue 20711 - object.update requires the "update" callback to wastefully return a copy of the updated value

https://github.com/dlang/druntime/pull/3012