Thread overview
[Issue 24700] MsCoffObj_getsegment is really slow O(n^2)
Aug 13
Dennis
Aug 13
Dennis
Aug 13
Dlang Bot
Aug 14
Dlang Bot
Oct 24
Dlang Bot
Oct 25
Dlang Bot
5 days ago
Dlang Bot
5 days ago
Dlang Bot
August 13
https://issues.dlang.org/show_bug.cgi?id=24700

--- Comment #1 from Dennis <dkorpel@live.nl> ---
N.b. even a dumb patch like this would mostly fix it, since it's trying to get
the same section over and over:
```
--- a/compiler/src/dmd/backend/mscoffobj.d
+++ b/compiler/src/dmd/backend/mscoffobj.d
@@ -1357,16 +1357,29 @@ int MsCoffObj_jmpTableSegment(Symbol *s)
 @trusted
 segidx_t MsCoffObj_getsegment(const(char)* sectname, uint flags)
 {
+    __gshared segidx_t lastFind = 1;
     //printf("getsegment(%s)\n", sectname);
     assert(strlen(sectname) <= 8);      // so it won't go into string_table
     if (!(flags & IMAGE_SCN_LNK_COMDAT))
     {
+        if (lastFind < SegData.length)
+        {
+            seg_data *pseg = SegData[lastFind];
+            if (!(ScnhdrTab[pseg.SDshtidx].Characteristics &
IMAGE_SCN_LNK_COMDAT) &&
+                strncmp(cast(const(char)* )ScnhdrTab[pseg.SDshtidx].Name,
sectname, 8) == 0)
+            {
+                //printf("\t%s\n", sectname);
+                return lastFind;         // return existing segment
+            }
+        }
+
         for (segidx_t seg = 1; seg < SegData.length; seg++)
         {   seg_data *pseg = SegData[seg];
             if (!(ScnhdrTab[pseg.SDshtidx].Characteristics &
IMAGE_SCN_LNK_COMDAT) &&
                 strncmp(cast(const(char)* )ScnhdrTab[pseg.SDshtidx].Name,
sectname, 8) == 0)
             {
                 //printf("\t%s\n", sectname);
+                lastFind = seg;
                 return seg;         // return existing segment
             }
         }
```

--
August 13
https://issues.dlang.org/show_bug.cgi?id=24700

--- Comment #2 from Dennis <dkorpel@live.nl> ---
Here's a test case to artificially produce similar Symbol / pointer ref counts:

```
static foreach (i; 0 .. 8_000)
{
    mixin("struct S"~i.stringof~" {float x;}");
}

__gshared int*[64_000] x;
```

Compile times goes from 35.5s => 2.4s after applying the patch I mentioned.

--
August 13
https://issues.dlang.org/show_bug.cgi?id=24700

--- Comment #3 from Dlang Bot <dlang-bot@dlang.rocks> ---
@dkorpel created dlang/dmd pull request #16780 "Bugzilla 24700 - Don't search for mscoff .dp$B section over and over" mentioning this issue:

- Bugzilla 24700 - Don't search for mscoff .dp$B section over and over

https://github.com/dlang/dmd/pull/16780

--
August 14
https://issues.dlang.org/show_bug.cgi?id=24700

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #16780 "Bugzilla 24700 - Don't search for mscoff .dp$B section over and over" was merged into master:

- 23d0c3dbf140ab6eb3ffa82dfddba03ac19b4861 by Dennis Korpel:
  Bugzilla 24700 - Don't search for mscoff .dp$B section over and over

https://github.com/dlang/dmd/pull/16780

--
October 24
https://issues.dlang.org/show_bug.cgi?id=24700

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
@veelo created dlang/dmd pull request #17029 "Bugzilla 24700 - Don't search for mscoff .dp$B section over and over …" mentioning this issue:

- Bugzilla 24700 - Don't search for mscoff .dp$B section over and over (#16780)

  (cherry picked from commit 67227f03e04368654d40ff707be7ee424b490e3b)

https://github.com/dlang/dmd/pull/17029

--
October 25
https://issues.dlang.org/show_bug.cgi?id=24700

--- Comment #6 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #17029 "Bugzilla 24700 - Don't search for mscoff .dp$B section over and over …" was merged into stable:

- 36b6061ce0c0fc1bd5497b1d83e30fb5215b2e2c by Dennis:
  Bugzilla 24700 - Don't search for mscoff .dp$B section over and over (#16780)

  (cherry picked from commit 67227f03e04368654d40ff707be7ee424b490e3b)

https://github.com/dlang/dmd/pull/17029

--
5 days ago
https://issues.dlang.org/show_bug.cgi?id=24700

--- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> ---
@kinke created dlang/dmd pull request #17069 "Merge stable" mentioning this issue:

- Bugzilla 24700 - Don't search for mscoff .dp$B section over and over (#16780)

  (cherry picked from commit 67227f03e04368654d40ff707be7ee424b490e3b)

https://github.com/dlang/dmd/pull/17069

--
5 days ago
https://issues.dlang.org/show_bug.cgi?id=24700

--- Comment #8 from Dlang Bot <dlang-bot@dlang.rocks> ---
dlang/dmd pull request #17069 "Merge stable" was merged into master:

- 2a63416b43cdf876e8818501f56a4ec441f053bf by Dennis:
  Bugzilla 24700 - Don't search for mscoff .dp$B section over and over (#16780)

  (cherry picked from commit 67227f03e04368654d40ff707be7ee424b490e3b)

https://github.com/dlang/dmd/pull/17069

--