sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Ruby performance on a Mac... am I just late to the party?

    Scheduled Pinned Locked Moved Developers' Forum
    26 Posts 4 Posters 3.0k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • thomthomT Offline
      thomthom
      last edited by

      It all boils down to Sketchup.set_status_text or Sketchup.status_text=. Remove them and the script runs fast.

      It seems that OSX always updates the UI even when plugins do heavy processing. As oppose to Windows where the UI stops responding.

      So I am guessing the lags comes from that and one should avoid updating the statusbar too often.

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        t=Time.now; 1000.times { |i| Sketchup.status_text = "Foo #{i}" }; puts Time.now - t

        OSX: 2.08987 (You see the statusbar update for each iteration.)
        Windows: 0.114 (You do see the statusbar update, but the text is a blur as it's much faster.)

        Conclusion: Sketchup.status_text= has very poor performance under OSX!

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • jeff hammondJ Offline
          jeff hammond
          last edited by

          hmm.. makes me wonder if those two lines are affecting performance of other plugins i have..

          here's a list of all the rubies i have which include those lines..

          (search term shown in top-right of finder window)

          screen 2011-01-30 at 1.39.57 PM.jpg

          that said, the only one of those listed rubies that i think could be sped up would be jointPushPull (and shapebender as i mentioned earlier).. if i run it on a more complex surface, it takes a while to complete but i just figured that's how it was.. maybe it's speed-upable on mac?

          (not saying that the others aren't affected.. it's just that i use JPP a lot and/or i'm feeding it more complex tasks where as the others that i use are more simple)

          dotdotdot

          1 Reply Last reply Reply Quote 0
          • thomthomT Offline
            thomthom
            last edited by

            @unknownuser said:

            hmm.. makes me wonder if those two lines are affecting performance of other plugins i have..

            It's a good possibility if they call these methods from within loops.
            I will have to profile some of my plugins under OSX.

            Thomas Thomassen — SketchUp Monkey & Coding addict
            List of my plugins and link to the CookieWare fund

            1 Reply Last reply Reply Quote 0
            • Dan RathbunD Offline
              Dan Rathbun
              last edited by

              @thomthom said:

              @dan rathbun said:

              And as we proved for .. in seems to run twice as fast as each.. but it's a platform difference.

              Platform difference?

              Sorry ... confusing run-on sentence. The second part was refering to the issue at hand, not the first part of the sentence. (I was tired, and my fingers were not keeping up with my brain. I should have made the last part a full sentence with a proper object.)

              Anyway.. you've found the culprit. We already know Ruby string handling can be slow.

              I would also suggest (I discussed this in another topic,) that when ever you need to send text to the statusbar, that you use a single quoted string for as much of it as possible with the string append operator << to add replacable portions.

              Sketchup.set_status_text("Please wait. Generating face #{face_num} of #{total} faces.")
              causes Ruby to parse the entire string for regular expressions, special characters ("\n",) and replacable parameters.
              I would use:
              Sketchup.set_status_text('Please wait. Generating face '<<"#{face_num.to_s} of #{total.to_s}"<<' faces.')
              or:
              Sketchup.set_status_text('Please wait. Generating face '<<face_num.to_s<<' of '<<total.to_s'<<' faces.')
              But NOT this:
              Sketchup.set_status_text('Please wait. Generating face '+face_num.to_s+' of '+total.to_s+' faces.')
              as the latter causes Ruby to create 9 string objects, and the former only 5.

              Another issue is needlessly updating the statusbar. If the resolution of a progressbar is say 20 '|' characters, then only update the progressbar on each 5% 'milestone' of the job completion (not every iteration.)

              The last issue (if OSX redraws the UI very often,) is to streamline UI object (menuitem and toolbar command,) validation procs. See the other topic: [code] Menu Validation (MF_DISABLED bugged on PC?)

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • thomthomT Offline
                thomthom
                last edited by

                @dan rathbun said:

                I would also suggest (I discussed this in another topic,) that when ever you need to send text to the statusbar, that you use a single quoted string for as much of it as possible with the string append operator << to add replacable portions.

                Sketchup.set_status_text("Please wait. Generating face #{face_num} of #{total} faces.")
                causes Ruby to parse the entire string for regular expressions, special characters ("\n",) and replacable parameters.
                I would use:
                Sketchup.set_status_text('Please wait. Generating face '<<"#{face_num.to_s} of #{total.to_s}"<<' faces.')
                or:
                Sketchup.set_status_text('Please wait. Generating face '<<face_num.to_s<<' of '<<total.to_s'<<' faces.')
                But NOT this:
                Sketchup.set_status_text('Please wait. Generating face '+face_num.to_s+' of '+total.to_s+' faces.')
                as the latter causes Ruby to create 9 string objects, and the former only 5.

                I think I read somewhere (was it The Ruby Programming Language? - and other places) that "string #{variable}" is the recommended way to generate strings with variables. The extra processing with double quotes was negligible. (Though I always use single quotes as default - remains of my PHP days.)
                ` > cls
                t=Time.now; total=100000; total.times { |i| x = "Please wait. Generating face #{i} of #{total} faces." }; puts Time.now-t
                0.22

                t=Time.now; total=100000; total.times { |i| x = 'Please wait. Generating face '<<"#{i.to_s} of #{total.to_s}"<<' faces.' }; puts Time.now-t
                0.393

                t=Time.now; total=10000; total.times { |i| x = 'Please wait. Generating face '<<i.to_s<<' of '<<total.to_s<<' faces.' }; puts Time.now-t
                0.029

                t=Time.now; total=10000; total.times { |i| x = 'Please wait. Generating face '+i.to_s+' of '+total.to_s+' faces.' }; puts Time.now-t
                0.024`

                @dan rathbun said:

                nother issue is needlessly updating the statusbar. If the resolution of a progressbar is say 20 '|' characters, then only update the progressbar on each 5% 'milestone' of the job completion (not every iteration.)

                This is where the main issue is at the moment when it comes to updating the statusbar. The generation of the strings are nothing compared.

                Thomas Thomassen — SketchUp Monkey & Coding addict
                List of my plugins and link to the CookieWare fund

                1 Reply Last reply Reply Quote 0
                • thomthomT Offline
                  thomthom
                  last edited by

                  Some more test data:

                  http://www.igvita.com/2008/07/08/6-optimization-tips-for-ruby-mri/
                  (The link to Chris Blackburn's site it links to is dead. But there's an archived version: http://replay.waybackmachine.org/20090212130913/http://blog.cbciweb.com/2008/06/10/ruby-performance-use-double-quotes-vs-single-quotes )
                  Interesting comment on this article: http://replay.waybackmachine.org/20090212130913/http://blog.cbciweb.com/2008/06/10/ruby-performance-use-double-quotes-vs-single-quotes#comment-49

                  http://blog.purepistos.net/index.php/2008/07/14/benchmarking-ruby-string-interpolation-concatenation-and-appending/

                  One thing that these test doesn't always mention is what Ruby version they where run on. That might make a difference. So the only reliable results is to try out in SketchUp.

                  Thomas Thomassen — SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 Reply Last reply Reply Quote 0
                  • T Offline
                    todd burch
                    last edited by

                    Ah! This is great. I had no idea. When I wrote progressbar, I could not spell Mac. And since I've moved to the Mac - I have never re-profiled. I will adjust the logic in progressbar to be a better citizen on the Mac.

                    I would have liked to have responded sooner, but I worked all weekend 'til the wee hours. Thank you all for your input and analysis. I would not have guessed it was the status bar updates. I have commented on the Ruby API doc.

                    Todd

                    1 Reply Last reply Reply Quote 0
                    • thomthomT Offline
                      thomthom
                      last edited by

                      @unknownuser said:

                      Ah! This is great. I had no idea. When I wrote progressbar, I could not spell Mac. And since I've moved to the Mac - I have never re-profiled. I will adjust the logic in progressbar to be a better citizen on the Mac.

                      I'd not have thought of checking this had you not made this post. I had made my own progress wrapper right before you posted. It ensures that the statusbar doesn't update more often than a given time, atm 0.1s. I need to check if this is still too quick.

                      @unknownuser said:

                      I have commented on the Ruby API doc.

                      👍 Good thinking.
                      I've reported the issue to Google. The lag we see under OSX seems unreasonable.

                      Thomas Thomassen — SketchUp Monkey & Coding addict
                      List of my plugins and link to the CookieWare fund

                      1 Reply Last reply Reply Quote 0
                      • T Offline
                        todd burch
                        last edited by

                        See my first post - I already reported.

                        1 Reply Last reply Reply Quote 0
                        • 1
                        • 2
                        • 2 / 2
                        • First post
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement