So, I found out that garrays are drawn inside the function plot_vis in g_template.c.<br><br>What I also found out is, that Tk drawing itself actually is already done the way I described: there is at most as many Tk elements drawn as the result of the relation between width of garray&#39;s graph and its X range. To simplify: if you have a garray of 10000 data fields and both width and X range of it&#39;s graph are set to 300 then the maximum amount of Tk elements (be it line segments or rectangles) drawn will be 300.<br>
This means that the Tk part of garray&#39;s visualisation is optimized.<br><br>Which in turn means that the slow part of drawing is acquiring data for coordinates of Tk elements. Now here come my thoughts about that: as I see functions in pd&#39;s code are heavily nested one inside the other. I mean, the tendency seams to be towards a large amount of rather small functions that call each other. I understand that code reusability is of value (this way you can draw garrays with the same piece of code as all pd&#39;s data structures created with the pd object &#39;struct&#39;), but in the case of garrays where heaps of data have to be processed/visualized it really slows the thing down. And it&#39;s also hard to find out what piece of code is actually slowing things down, when the program has to make hundreds of calls to perform one intuitively simple task. I think in such a case there should be a dedicated code optimized to work fast with large quantity of data.<br>
<br>Here I see two possibilities:<br>1. We could add some code to template.c that would treat garrays differently. Though I&#39;m not sure if one can know from inside the plot_vis function whether a garray&#39;s data is being drawn or it is something else.<br>
2. We could already on the level of garray redirect calls to functions that result in plot_vis drawing garray&#39;s data to some dedicated drawing functions for garrays.<br><br>If someone has thought on these proposals or any ideas, please comment.<br>
<br>One other &quot;bug&quot; I noticed that also slows things down but is of totally different nature I suppose: every object that is drawn via &#39;graph on parent&#39; is being constantly deleted and recreated (in terms of Tk messages) when you drag it&#39;s nesting subpatch around the parent patch. This results in the same behaviour for garrays, because they are always drawn in the &#39;graph on parent&#39; manner.<br>
<br>J.<br><br><div class="gmail_quote">On Sun, Apr 13, 2008 at 6:55 PM, Hans-Christoph Steiner &lt;<a href="mailto:hans@eds.org">hans@eds.org</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div style="">
<div><br></div><div>Hey,</div><div><br></div><div>I am also quite interested in your code and the stuff you&#39;ve written about, could provide links to both?</div><div><br></div><div>About the array code, a good place to start is in pd/src/g_array.c. &nbsp;Take a look there, and feel free to post any questions on this list so we can answer them.</div>
<div><br></div><font color="#888888"><div>.hc</div></font><div><div></div><div class="Wj3C7c"><br><div>On Apr 13, 2008, at 11:54 AM, Jakob Leben wrote:<br><blockquote type="cite">Hello to all the PD developers!<br><br>As the word goes about improving pd&#39;s GUI speed, I thought this is the perfect opportunity for me to share some ideas, that I&#39;ve already written about on the <a href="http://puredata.info" target="_blank">puredata.info</a> homepage.<br>
 <br>Let me introduce myself first. My name is Jakob Leben, I&#39;m from Slovenia and I&#39;m actively using pure data. I can say I have quite some experience with writing pd externals, but I don&#39;t have an integral insight into pd&#39;s source code.<br>
 <br>Lately I made an external that visualizes pd&#39;s graphic arrays but much faster than pd natively does. (If I load 20 seconds of audio into a pd&#39;s array the drawing of the array causes clicks in audio. Another big problem is dragging a graphic array around the patch, that works extra slow.<br>
 <br>There are two things one could do:<br>1. change the algorithm for visualisation of array&#39;s data.<br>2. draw the data onto a specially loaded Tk canvas, so that when dragging the array around only the canvas&#39; window is translated instead of all the coordinates for the line that represents data.<br>
 <br>Detailed explanation:<br>1. When the width of array&#39;s visualisation in pixels is smaller than the number of samples written into array it&#39;s useless to draw a segment of the line for each sample of data. Instead you can only draw one vertical segment of line for each column of pixels drawn: this segment&#39;s endpoints are defined by the minimum and the maximum value of the range of data that is &quot;covered&quot; by this pixel.<br>
 The result of this is exactly the same as the way arrays are drawn now, though it involves much less line segments being drawn.<br>2. There is one problem that I came across with using a special canvas to visualise an array: a click on that canvas doesn&#39;t select the pd object that lies &quot;under&quot; this canvas. This canvas will always be &quot;above&quot; the object as all the objects are only items of one single Tk canvas, while this new canvas is the general canvas&#39; child displayed as a general canvas&#39; item of type window. Tk rule is that items of type window are always &quot;above&quot; all other items on a canvas.<br>
 Thus it would be necessary to make a new binding for mouse events to this new canvas and somehow pass that click to pd&#39;s object.<br><br>Now, I realized these ideas in the form of a pd extern that visualises an array, but i think it would be great to integrate those ideas into pd&#39;s arrays itself. I could do that if only I understood better how PD&#39;s arrays are drawn and how the selection of pd&#39;s object works... I tried but it seems to my like too big a project to dig out myself where in the code and how those things happen so I would appreciate very much if someone guided me through this.<br>
 <br>I&#39;m willing to put all my effort into making those arrays draw faster.<br><br>Sincerely,<br>Jakob Leben<br><br><div class="gmail_quote">On Sat, Apr 12, 2008 at 9:01 PM, Hans-Christoph Steiner &lt;<a href="mailto:hans@eds.org" target="_blank">hans@eds.org</a>&gt; wrote:<br>
 <blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br> It seems there is a profiler for Tcl. &nbsp;Has anyone ever tried it on Pd?<br> <br> Begin forwarded message:<br>
 &gt; From: Revar Desmera &lt;<a href="mailto:revarbat@gmail.com" target="_blank">revarbat@gmail.com</a>&gt;<br> &gt; Date: April 9, 2008 10:58:55 PM EDT<br> &gt; To: TCL-Mac List &lt;<a href="mailto:tcl-mac@lists.sourceforge.net" target="_blank">tcl-mac@lists.sourceforge.net</a>&gt;<br>
 &gt; Subject: Re: [MACTCL] Improving Application GUI Speed<br> &gt; Delivered-To: <a href="mailto:hans@eds.org" target="_blank">hans@eds.org</a><br> &gt; X-Mailer: Apple Mail (2.919.2)<br> &gt; X-Filter-Rule: ALL_LISTS<br>
 &gt;<br> &gt; If you download <a href="http://www.belfry.com/code/profile.tcl" target="_blank">http://www.belfry.com/code/profile.tcl</a>, and add a<br> &gt; &#39;source profile.tcl&#39; to the beginning of your program, when the<br>
 &gt; program finishes, it&#39;ll dump a very detailed timing profile of your<br> &gt; code to tclprof.txt, which you can use to determine what to optimize.<br> &gt; The report format is very close to that of gprof.<br> &gt;<br>
 &gt; &nbsp; &nbsp; &nbsp; - Revar<br> &gt;<br> &gt;<br> &gt;<br> &gt; On Apr 8, 2008, at 1:10 AM, Randolf Schultz wrote:<br> &gt;&gt; Hello,<br> &gt;&gt;<br> &gt;&gt; please help me getting my application up to speed on MacOSX/Aqua.<br>
 &gt;&gt; It runs fine on Linux/X11, Win32, and even MacOSX/X11. Only on<br> &gt;&gt; MacOSX/Aqua it crawls.<br> &gt;&gt;<br> &gt;&gt; Want to have a look first?<br> &gt;&gt; Go to<br> &gt;&gt;<br> &gt;&gt; <a href="http://sourceforge.net/project/platformdownload.php" target="_blank">http://sourceforge.net/project/platformdownload.php</a>?<br>
 &gt;&gt; group_id=28460&amp;sel_platform=4542<br> &gt;&gt;<br> &gt;&gt; (or <a href="http://www.ayam3d.org/download.html" target="_blank">http://www.ayam3d.org/download.html</a>)<br> &gt;&gt;<br> &gt;&gt; get both variants (MacOSX/X11 and MacOSX/Aqua).<br>
 &gt;&gt;<br> &gt;&gt; Already the application startup is 2-3s (Linux/X11) vs. 10-15s<br> &gt;&gt; (MacOSX/Aqua); from then on the MacOSX version is unusably<br> &gt;&gt; slow, especially when drawing the scrollable GUIs for the object<br>
 &gt;&gt; properties (those are implemented as window in a canvas).<br> &gt;&gt; Another problem area are the pane widgets, that may be dragged<br> &gt;&gt; quite fine on X11, but on Aqua they do one hop every 1-2s (and<br>
 &gt;&gt; this is _without_ continuous re-packing the GUI, only dragging<br> &gt;&gt; the pane handle, which is a simple packed frame IIRC!).<br> &gt;&gt;<br> &gt;&gt; The Linux/X11 and MacOSX/Aqua variants were test-run on the<br>
 &gt;&gt; very same machine (MacMini-PPC)!<br> &gt;&gt;<br> &gt;&gt; So how would you proceed to tackle this problem?<br> &gt;&gt; Is there an easy way to profile such complex scenarios with Tcl/Tk?<br> &gt;&gt;<br> &gt;&gt; best regards,<br>
 &gt;&gt; Randolf<br> &gt;&gt;<br> &gt;&gt; ---------------------------------------------------------------------<br> &gt;&gt; ----<br> &gt;&gt; This SF.net email is sponsored by the 2008 JavaOne(SM) Conference<br> &gt;&gt; Register now and save $200. Hurry, offer ends at 11:59 p.m.,<br>
 &gt;&gt; Monday, April 7! Use priority code J8TLD2.<br> &gt;&gt; <a href="http://ad.doubleclick.net/clk;198757673;13503038;p?http://" target="_blank">http://ad.doubleclick.net/clk;198757673;13503038;p?http://</a><br> &gt;&gt; <a href="http://java.sun.com/javaone" target="_blank">java.sun.com/javaone</a><br>
 &gt;&gt; _______________________________________________<br> &gt;&gt; Tcl-mac mailing list<br> &gt;&gt; <a href="mailto:tcl-mac@lists.sourceforge.net" target="_blank">tcl-mac@lists.sourceforge.net</a><br> &gt;&gt; <a href="https://lists.sourceforge.net/lists/listinfo/tcl-mac" target="_blank">https://lists.sourceforge.net/lists/listinfo/tcl-mac</a><br>
 &gt;<br> &gt;<br> &gt; ----------------------------------------------------------------------<br> &gt; ---<br> &gt; This SF.net email is sponsored by the 2008 JavaOne(SM) Conference<br> &gt; Don&#39;t miss this year&#39;s exciting event. There&#39;s still time to save<br>
 &gt; $100.<br> &gt; Use priority code J8TL2D2.<br> &gt; <a href="http://ad.doubleclick.net/clk;198757673;13503038;p?http://" target="_blank">http://ad.doubleclick.net/clk;198757673;13503038;p?http://</a><br> &gt; <a href="http://java.sun.com/javaone" target="_blank">java.sun.com/javaone</a><br>
 &gt; _______________________________________________<br> &gt; Tcl-mac mailing list<br> &gt; <a href="mailto:tcl-mac@lists.sourceforge.net" target="_blank">tcl-mac@lists.sourceforge.net</a><br> &gt; <a href="https://lists.sourceforge.net/lists/listinfo/tcl-mac" target="_blank">https://lists.sourceforge.net/lists/listinfo/tcl-mac</a><br>
 <br> <br> <br> ------------------------------------------------------------------------<br> ----<br> <br> Using ReBirth is like trying to play an 808 with a long stick. &nbsp; &nbsp;-<br> David Zicarelli<br> <br> <br> <br> _______________________________________________<br>
 PD-dev mailing list<br> <a href="mailto:PD-dev@iem.at" target="_blank">PD-dev@iem.at</a><br> <a href="http://lists.puredata.info/listinfo/pd-dev" target="_blank">http://lists.puredata.info/listinfo/pd-dev</a><br> </blockquote>
</div><br></blockquote></div><br></div></div><div> <span style="border-collapse: separate; border-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><br>
<span style="border-collapse: separate; border-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><div>
<br></div><div>----------------------------------------------------------------------------</div><div class="Ih2E3d"><div><br></div><div>Using ReBirth is like trying to play an 808 with a long stick. &nbsp; &nbsp;-David Zicarelli</div>
<br></div></span></span> </div><br></div></blockquote></div><br>