Shopify / seafoam

A tool for working with compiler graphs dumped by the GraalVM compiler
MIT License
126 stars 22 forks source link

Simplify Truffle allocations #62

Closed chrisseaton closed 2 years ago

chrisseaton commented 2 years ago

Works by hiding null and zero fields in object allocations. Removes a ton of nodes and edges that don't tell you anything.

Before:

flowchart TD
  node0("0 Start")
  style node0 fill:#e98693,stroke:black,color:#1a1919;
  node1222("1222 Return")
  style node1222 fill:#e98693,stroke:black,color:#1a1919;
  node1580("1580 VirtualInstance(0) org.truffleruby.core.basicobject.RubyBasicObject")
  style node1580 fill:#f9f9f9,stroke:black,color:#1a1919;
  node1726("1726 Unbox")
  style node1726 fill:#f9f9f9,stroke:black,color:#1a1919;
  node1730("1730 Unbox")
  style node1730 fill:#f9f9f9,stroke:black,color:#1a1919;
  node1745{{"1745 SignExtend"}}
  style node1745 fill:#3cb4a4,stroke:black,color:#1a1919;
  node1780{{"1780 SignExtend"}}
  style node1780 fill:#3cb4a4,stroke:black,color:#1a1919;
  node2163("2163 Alloc")
  style node2163 fill:#da2d4f,stroke:black,color:#ffffff;
  node2164("2164 AllocatedObject")
  style node2164 fill:#343d46,stroke:black,color:#ffffff;
  node2164 --> node1222
  linkStyle 0 stroke:#3cb4a4,stroke-width:px;
  node1726 --> node1730
  linkStyle 1 stroke:#da2d4f,stroke-width:2px;
  node1730 --> node2163
  linkStyle 2 stroke:#da2d4f,stroke-width:2px;
  node1726 --> node1745
  linkStyle 3 stroke:#3cb4a4,stroke-width:px;
  node1730 --> node1780
  linkStyle 4 stroke:#3cb4a4,stroke-width:px;
  node1580 --> node2163
  linkStyle 5 stroke:#3cb4a4,stroke-width:px;
  inline1779x2163(["1779 C(ShapeBasic@2939f27)"])
  style inline1779x2163 fill:#d7ede7,stroke:black,color:#1a1919;
  inline1779x2163 --> node2163
  linkStyle 6 stroke:#3cb4a4,stroke-width:px;
  inline41x2163(["41 C(Object[null])"])
  style inline41x2163 fill:#d7ede7,stroke:black,color:#1a1919;
  inline41x2163 --> node2163
  linkStyle 7 stroke:#3cb4a4,stroke-width:px;
  inline41x2163(["41 C(Object[null])"])
  style inline41x2163 fill:#d7ede7,stroke:black,color:#1a1919;
  inline41x2163 --> node2163
  linkStyle 8 stroke:#3cb4a4,stroke-width:px;
  inline765x2163(["765 C(RubyClass@7a583586)"])
  style inline765x2163 fill:#d7ede7,stroke:black,color:#1a1919;
  inline765x2163 --> node2163
  linkStyle 9 stroke:#3cb4a4,stroke-width:px;
  inline41x2163(["41 C(Object[null])"])
  style inline41x2163 fill:#d7ede7,stroke:black,color:#1a1919;
  inline41x2163 --> node2163
  linkStyle 10 stroke:#3cb4a4,stroke-width:px;
  node1745 --> node2163
  linkStyle 11 stroke:#3cb4a4,stroke-width:px;
  node1780 --> node2163
  linkStyle 12 stroke:#3cb4a4,stroke-width:px;
  inline1542x2163(["1542 C(0)"])
  style inline1542x2163 fill:#d7ede7,stroke:black,color:#1a1919;
  inline1542x2163 --> node2163
  linkStyle 13 stroke:#3cb4a4,stroke-width:px;
  inline41x2163(["41 C(Object[null])"])
  style inline41x2163 fill:#d7ede7,stroke:black,color:#1a1919;
  inline41x2163 --> node2163
  linkStyle 14 stroke:#3cb4a4,stroke-width:px;
  inline41x2163(["41 C(Object[null])"])
  style inline41x2163 fill:#d7ede7,stroke:black,color:#1a1919;
  inline41x2163 --> node2163
  linkStyle 15 stroke:#3cb4a4,stroke-width:px;
  inline41x2163(["41 C(Object[null])"])
  style inline41x2163 fill:#d7ede7,stroke:black,color:#1a1919;
  inline41x2163 --> node2163
  linkStyle 16 stroke:#3cb4a4,stroke-width:px;
  node2163 --> node1222
  linkStyle 17 stroke:#da2d4f,stroke-width:2px;
  node1580 --> node2164
  linkStyle 18 stroke:#3cb4a4,stroke-width:px;
  node2163 --> node2164
  linkStyle 19 stroke:#3cb4a4,stroke-width:px;
  node0 --> node1726
  linkStyle 20 stroke:#da2d4f,stroke-width:2px;
  inline2173x1726(["2173 T(8)"])
  style inline2173x1726 fill:#d7ede7,stroke:black,color:#1a1919;
  inline2173x1726 --> node1726
  linkStyle 21 stroke:#3cb4a4,stroke-width:px;
  inline2174x1730(["2174 T(9)"])
  style inline2174x1730 fill:#d7ede7,stroke:black,color:#1a1919;
  inline2174x1730 --> node1730
  linkStyle 22 stroke:#3cb4a4,stroke-width:px;

After:

flowchart TD
  node0("0 Start")
  style node0 fill:#e98693,stroke:black,color:#1a1919;
  node1222("1222 Return")
  style node1222 fill:#e98693,stroke:black,color:#1a1919;
  node1580("1580 VirtualInstance(0) org.truffleruby.core.basicobject.RubyBasicObject")
  style node1580 fill:#f9f9f9,stroke:black,color:#1a1919;
  node1726("1726 Unbox")
  style node1726 fill:#f9f9f9,stroke:black,color:#1a1919;
  node1730("1730 Unbox")
  style node1730 fill:#f9f9f9,stroke:black,color:#1a1919;
  node1745{{"1745 SignExtend"}}
  style node1745 fill:#3cb4a4,stroke:black,color:#1a1919;
  node1780{{"1780 SignExtend"}}
  style node1780 fill:#3cb4a4,stroke:black,color:#1a1919;
  node2163("2163 Alloc")
  style node2163 fill:#da2d4f,stroke:black,color:#ffffff;
  node2164("2164 AllocatedObject")
  style node2164 fill:#343d46,stroke:black,color:#ffffff;
  node2164 --> node1222
  linkStyle 0 stroke:#3cb4a4,stroke-width:px;
  node1726 --> node1730
  linkStyle 1 stroke:#da2d4f,stroke-width:2px;
  node1730 --> node2163
  linkStyle 2 stroke:#da2d4f,stroke-width:2px;
  node1726 --> node1745
  linkStyle 3 stroke:#3cb4a4,stroke-width:px;
  node1730 --> node1780
  linkStyle 4 stroke:#3cb4a4,stroke-width:px;
  node1580 --> node2163
  linkStyle 5 stroke:#3cb4a4,stroke-width:px;
  inline1779x2163(["1779 C(ShapeBasic@2939f27)"])
  style inline1779x2163 fill:#d7ede7,stroke:black,color:#1a1919;
  inline1779x2163 --> node2163
  linkStyle 6 stroke:#3cb4a4,stroke-width:px;
  inline765x2163(["765 C(RubyClass@7a583586)"])
  style inline765x2163 fill:#d7ede7,stroke:black,color:#1a1919;
  inline765x2163 --> node2163
  linkStyle 7 stroke:#3cb4a4,stroke-width:px;
  node1745 --> node2163
  linkStyle 8 stroke:#3cb4a4,stroke-width:px;
  node1780 --> node2163
  linkStyle 9 stroke:#3cb4a4,stroke-width:px;
  node2163 --> node1222
  linkStyle 10 stroke:#da2d4f,stroke-width:2px;
  node1580 --> node2164
  linkStyle 11 stroke:#3cb4a4,stroke-width:px;
  node2163 --> node2164
  linkStyle 12 stroke:#3cb4a4,stroke-width:px;
  node0 --> node1726
  linkStyle 13 stroke:#da2d4f,stroke-width:2px;
  inline2173x1726(["2173 T(8)"])
  style inline2173x1726 fill:#d7ede7,stroke:black,color:#1a1919;
  inline2173x1726 --> node1726
  linkStyle 14 stroke:#3cb4a4,stroke-width:px;
  inline2174x1730(["2174 T(9)"])
  style inline2174x1730 fill:#d7ede7,stroke:black,color:#1a1919;
  inline2174x1730 --> node1730
  linkStyle 15 stroke:#3cb4a4,stroke-width:px;
chrisseaton commented 2 years ago

@eregon

eregon commented 2 years ago

Right, since those are default values anyway.

I was thinking to reduce the VirtualInstance+Alloc+AllocatedObject to a single node (or maybe 2 if that makes more sense).

chrisseaton commented 2 years ago

Not sure why they end up in this verbose, lowered, tri-node state - we never see NewInstanceNode in Truffle graphs.

eregon commented 1 year ago

Not sure why they end up in this verbose, lowered, tri-node state - we never see NewInstanceNode in Truffle graphs.

Maybe because we're after PEA?