Bug 2181 – Constant-time std.gc.removeRange

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
phobos
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2008-06-26T18:11:00Z
Last change time
2014-11-22T23:30:24Z
Keywords
patch
Assigned to
bugzilla
Creator
default_357-line

Attachments

IDFilenameSummaryContent-TypeSize
260phobos_gc_constant_time_removeRange.patchGC patch for constant-time removeRangetext/plain4139

Comments

Comment #0 by default_357-line — 2008-06-26T18:11:14Z
When profiling my StackThreads benchmark, I discovered that removeRange was taking up 90+% of my time. Looking deeper, this seems to be because removeRange always scans the complete array of ranges until it finds the correct one. The proposed patch adds an optional size_t pointer to addRange, which points to a variable intended to store the current index of the added range in the ranges array. It is stored as a new field in the Range struct, and operations that shuffle ranges around (like removeRange), update it. Then, when removing a range, the pointer is passed to an overloaded removeRange (in the form of a ref parameter, to prevent a race condition [see NG]). The overloaded removeRange replaces the pointed-to index with the last index in the array (updating its pointer), then reduces array size by one. In my benchmark, this patch reduced time in removeRange to negligible, and since it doesn't interact with the rest of Phobos, it shouldn't cause any problems. I thus request its inclusion into mainline Phobos 2. Since 1 is supposed to be stable, I do not expect it to be included in Phobos1, although I will continue to use it myself. Thanks for any feedback, --feep
Comment #1 by default_357-line — 2008-06-26T18:11:58Z
Created attachment 260 GC patch for constant-time removeRange
Comment #2 by briancschott — 2014-07-07T16:38:18Z
addRange and removeRange are now log(n) since this pull request was merged: https://github.com/D-Programming-Language/druntime/pull/788/ I think we can close this.
Comment #3 by code — 2014-11-22T23:30:24Z