Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Conversation

@mikedn
Copy link

@mikedn mikedn commented Nov 9, 2017

Currently SsaBuilder uses comp->getAllocator() in a lot of places so a lot of the memory it allocates lands in CMK_Generic instead of CMK_SSA.

Same for CopyProp phase.

Currently SsaBuilder use comp->getAllocator() in a lot of places so a lot of the memory it allocates lands in CMK_Generic instead of CMK_SSA.

Same for CopyProp phase.
@mikedn
Copy link
Author

mikedn commented Nov 9, 2017

JitMemStats diff:

-                   SSA |   36352868 |   1.97%
+                   SSA |   90515140 |   4.92%
            ValueNumber |  345182286 |  18.75%
-              LvaTable |   86994265 |   4.72%
+              LvaTable |   86994265 |   4.73%
             UnwindInfo |     197280 |   0.01%
                 hashBv |    5911128 |   0.32%
                 bitset |   26976168 |   1.47%
           FixedBitVect |       7028 |   0.00%
-               Generic |  141367200 |   7.68%
+               Generic |   43900160 |   2.38%
         IndirAssignMap |     139904 |   0.01%
          FieldSeqStore |    4820344 |   0.26%
                LoopOpt |      66360 |   0.00%
              LoopHoist |    1615000 |   0.09%
                Unknown |   18985445 |   1.03%
             RangeCheck |    9590968 |   0.52%
+              CopyProp |   42872960 |   2.33%

@mikedn
Copy link
Author

mikedn commented Nov 9, 2017

So SSA memory usage is more than double than previously recorded. And judging by the changes I have made most of this additional memory usage comes from dominance computation, that one uses JitHashTable as if it's the only data structure in the galaxy...

@sandreenko
Copy link

So SSA memory usage is more than double than previously recorded. And judging by the changes I have made most of this additional memory usage comes from dominance computation, that one uses JitHashTable as if it's the only data structure in the galaxy...

Do we have any hacks to use std:: structs for local experiments? I miss them so much.

@mikedn
Copy link
Author

mikedn commented Nov 9, 2017

Do we have any hacks to use std:: structs for local experiments? I miss them so much.

Interesting idea. I suppose that if you include the compiler's own std headers and define jitstd as std it might work... or get a zillion compilation errors.

The JIT is really in a bad spot with regards to data structures. jitstd is usable but incomplete and out of date - list has emplace (heh, I think I added that) but vector does not, allocator is an old style allocator that's kind of horrible etc. Improving jitstd isn't easy (I'm not even sure who had the courage to write all that to begin with). We also have non-jitstd containers like JitHashTable, JitExpandArray, ArrayStack, SmallHashTable - some better, some worse and none really good. Oh well.

But in the specific case of SSA dominance computation the data structure implementation is less of a problem, JitHashTable is reasonable. The problem is the choice of data structure - hashtables are used when faster and smaller data structures would do - vectors, plain arrays, maybe a hashbv here and there.

Working on it, preliminary results look pretty good.

@mikedn
Copy link
Author

mikedn commented Nov 9, 2017

One example of improvement in #14965. The dominator tree is currently something like map<bb*, map<bb*, bool>> - maps each block to its children in the dominator tree. map<bb*, bool> can be vector<bb*> because:

  • Dominator tree walkers just don't need anything more sophisticated than that.
  • The dominator tree is built by visiting each block exactly once and adding it to its immediate dominator's children "set". That excludes the possibility of adding the same block twice to a given set.

@sandreenko
Copy link

Changes in this PR looks good to me.

I think @BruceForstall knows the historical context of these jitstd structs decisions, maybe some of them are outdated and we can change them now.

cc @dotnet/jit-contrib

@mikedn
Copy link
Author

mikedn commented Nov 10, 2017

It looks like there's still some memory that's not properly accounted for. Both SSA and CopyProp use ArrayStack and that one doesn't use CompAllocator, it goes directly to Compiler and always allocates CMK_ArrayStack memory. I'll look into changing ArrayStack to use CompAllocator but that will be another PR.

Copy link

@CarolEidt CarolEidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I wouldn't mind having @BruceForstall or @briansull also take a look, and perhaps comment on the history of jitstd. As I (barely) recall, its origins arose around both some limitations of older compilers we were constrained to use, along with some other dependencies that made the use of std:: not possible.

@mikedn
Copy link
Author

mikedn commented Nov 13, 2017

Another bit of memory that belongs to SSA but ends up in the CMK_Generic bucket is the "PerSsaArray". That too is something I'll look at in a future PR.

@BruceForstall
Copy link

We generally can't use STL (aka std::) in code that links with the PAL (including the JIT). Trying to do so leads to a zillion compilation errors on various platforms, related to utilcode. One of the biggest issues is that wchar_t is 32-bits on Linux and 16-bits on Windows, and that shows through with std::string/std::wstring. ToolBox\SOS\Strike actually does use it, with some number of hacks. I tried to use it for superpmi, but then gave up and added even more stuff in src\inc\clr_std (namely, string).

Historically, we also had issues with compiling using toolsets that didn't support STL. And issues with the STL exception handling mode, too, I think.

@BruceForstall BruceForstall merged commit 189ffe1 into dotnet:master Nov 14, 2017
@mikedn mikedn deleted the ssa-mem-track branch December 16, 2017 09:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants