<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"><meta name="Generator" content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        text-align:right;
        direction:rtl;
        unicode-bidi:embed;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        text-align:right;
        direction:rtl;
        unicode-bidi:embed;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
span.EmailStyle19
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.EmailStyle20
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle21
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle22
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle23
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.WordSection1
        {page:WordSection1;}
--></style></head><body lang="EN-US" link="blue" vlink="purple"><div class="WordSection1"><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">After further testing I find very weird behaviors of the Jit.</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">For instance, looks like if use some pattern too many times, The Jit counter goes to infinity, while otherwise it stabilizes.</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">It would be very helpful to get printouts from ipy whenever it creates an a object that requires jitting.</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">Are there a few places I can Console.writeline in the IronPython code that should cover most of these cases?</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">Is there any cache mechanism you are aware of, that might cause this behavior where &quot;over usage&quot; generates infinite Jitting?</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D"> </span></p><div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
<b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Dino Viehland<br>
<b>Sent:</b> Monday, November 29, 2010 8:23 PM<br><b>To:</b> Discussion of IronPython<br><b>Subject:</b> Re: [IronPython] Jit leak in defaultdict for Ipy 2.6.2</span></p></div></div><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
 </p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">The closest non-windbg solution I could think of might be CLR Profiler which can probably report the number of dynamic method objects which are alive.  Windbg can also do this when you dump the heap and is probably over all actually easier to use in this case as you can attach, do !DumpHeap –stat, and then detach.</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D"> </span></p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">Just one more data point which might help you understand what’s going on – the JITed methods in this case are probably adding 4k of memory to the cost of each defaultdict instance as long as the defaultdict is alive.</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D"> </span></p><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt"><div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Idan Zaltzberg<br>
<b>Sent:</b> Monday, November 29, 2010 9:59 AM<br><b>To:</b> Discussion of IronPython<br><b>Subject:</b> Re: [IronPython] Jit leak in defaultdict for Ipy 2.6.2</span></p></div></div><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
 </p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">Thanks.</span></p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">How I suspect there is a leak in the JIT of my application, up until now I thought that if the performance counter for &quot;# of methods jitted&quot; is constantly rising then that means exactly that. From your reply I understand that this is not the case.</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">Can you tell how can I know how many uncollectible JIT objects I have so that I can trace them (preferably without using windbg)</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D"> </span></p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">Thanks again…</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D"> </span></p><div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in"><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
<b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Dino Viehland<br>
<b>Sent:</b> Monday, November 29, 2010 7:41 PM<br><b>To:</b> Discussion of IronPython<br><b>Subject:</b> Re: [IronPython] Jit leak in defaultdict for Ipy 2.6.2</span></p></div></div><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
 </p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D">Defaultdict is creating a new invoke binder – it should be getting the binder from PythonContext using the Invoke(CallSignature) method.  Because it creates a new binder each time we are getting no caching of the rules across defaultdict instances and it’ll end up generating a new method to handle the missing call.  It is collectible (so not really a leak) but it is really bad from a performance perspective.</span></p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><span style="color:#1F497D"> </span></p><div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt"><div><div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> <a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com">users-bounces@lists.ironpython.com</a>] <b>On Behalf Of </b>Idan Zaltzberg<br>
<b>Sent:</b> Monday, November 29, 2010 4:10 AM<br><b>To:</b> Discussion of IronPython<br><b>Subject:</b> [IronPython] Jit leak in defaultdict for Ipy 2.6.2</span></p></div></div><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
 </p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">Hi,</p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">I have noticed the following method always adds a jitted method (looking at the &quot;.NET CLR Jit&quot; performance counter) when it is run:</p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">def f():</p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">                d = defaultdict(int)</p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
                d[0]</p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"> </p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">I created my own implementation of defaultdict (in ipy):</p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">class defaultdict(dict):</p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">    def __init__(self, cls):</p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
        super(defaultdict, self).__init__()</p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">        self.cls = cls</p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
    def __getitem__(self, key):</p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">        if key not in self:</p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
            self[key] = self.cls()</p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">        return super(defaultdict, self).__getitem__(key)</p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
 </p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">And I noticed that it does not leak JIT and it works 200 times faster when running the method f().</p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
Can you please look why this happens in the current implementation?</p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">Also I was wondering if there are any other utility methods that use similar code and probably will have the same problem.</p>
<p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"> </p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">Thanks, </p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed">
Idan zalzberg</p><p class="MsoNormal" style="text-align:left;direction:ltr;unicode-bidi:embed"> </p></div></div></div></body></html>