Thread overview
[Issue 1923] New: GC optimization for contiguous pointers to the same page
Mar 14, 2008
d-bugmail
Mar 14, 2008
d-bugmail
Mar 28, 2009
d-bugmail
Mar 28, 2009
d-bugmail
Mar 29, 2009
d-bugmail
Mar 29, 2009
d-bugmail
Mar 29, 2009
d-bugmail
Mar 29, 2009
Sean Kelly
Apr 01, 2009
d-bugmail
March 14, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1923

           Summary: GC optimization for contiguous pointers to the same page
           Product: D
           Version: 1.028
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: patch
          Severity: enhancement
          Priority: P3
         Component: Phobos
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: thecybershadow@gmail.com


Probably the best practical example for this situation is splitting a large text file by whitespace:

import std.file, std.string, std.gc;
import std.stdio: putr = writefln;
alias char[] string;
static import std.c.time;
double clock() {
    auto t = std.c.time.clock();
    return t/cast(double)std.c.time.CLOCKS_PER_SEC;
}
void main() {
  //disable;
  auto t0 = clock();
  auto txt = cast(string)read("text.txt"); // 6.3 MB of text
  auto t1 = clock();
  auto words = txt.split();
  auto t2 = clock();

  putr("loading time: ", t1 - t0); // 0.08 s
  putr("splitting time: ", t2 - t1); // 3.69 s with GC, 0.66 s without
  // Total running time with GC = 10.85 s
}

Example is from this NG post by bearophile:

http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=67673

The attached patch increases the performance of this particular case tenfold by my tests. It should have no significant overhead on other situations. There's a bit more info in my reply to the abovementioned NG post.


-- 

March 14, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1923





------- Comment #1 from thecybershadow@gmail.com  2008-03-14 03:11 -------
Created an attachment (id=239)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=239&action=view)
Proposed patch

Tested myself on a >10000 line application, didn't notice any ill side-effects.


-- 

March 28, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=1923





------- Comment #2 from llucax@gmail.com  2009-03-28 15:17 -------
Is there any reason why this patch is no applied?


-- 

March 28, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=1923





------- Comment #3 from dhasenan@gmail.com  2009-03-28 15:50 -------
For reference, this patch has been applied to Tango and has not caused any known issues.


-- 

March 29, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=1923





------- Comment #4 from bugzilla@digitalmars.com  2009-03-29 01:54 -------
Complete discussion:

http://www.digitalmars.com/d/archives/digitalmars/D/Slow_GC_67673.html


-- 

March 29, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=1923





------- Comment #5 from bugzilla@digitalmars.com  2009-03-29 02:05 -------
This patch is already in D2, I'll add it to D1.


-- 

March 29, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=1923





------- Comment #6 from llucax@gmail.com  2009-03-29 10:15 -------
But for some reason D2 (druntime) timings are still huge.

Here is a test, dmd es 1.041 with the patch attached here, dmd2 is 2.026.

$ cat split.d
// Written by bearophile <bearophileHUGS@lycos.com>
// Fount at
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=67673
// Sightly modified by Leandro Lucarella <llucax@gmail.com>
// (removed timings)

import std.file, std.string;
import std.stdio: writefln;
static import std.c.time;

void main() {
        auto txt = cast(string) read("split.txt");
        auto words = txt.split();
}

$ dmd -release -O -inline -ofsplit1 split.d
$ dmd2 -release -O -inline -ofsplit2 split.d
$ ls -lh split.txt
-rw-r--r-- 1 luca luca 15M mar 28 17:01 split.txt
$ time ./split1

real    0m0.751s
user    0m0.443s
sys     0m0.128s
$ time ./split2

real    0m25.293s
user    0m20.517s
sys     0m0.233s

(timings for D1 without the patch are about the same as D2)


-- 

March 29, 2009
d-bugmail@puremagic.com wrote:
>
> But for some reason D2 (druntime) timings are still huge.

Have you timed Tango?  The GC implementations are roughly the same.
April 01, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=1923


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #7 from bugzilla@digitalmars.com  2009-04-01 13:51 -------
Fixed DMD 1.042


--