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

    Optimization Tips

    Scheduled Pinned Locked Moved Developers' Forum
    110 Posts 22 Posters 168.8k Views 22 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.
    • W Offline
      Whaat
      last edited by

      I noticed in that thread about adding geometry to the model that someone tried creating the geometry by writing the mesh out to a temporary file format and then importing presumably with the model.import method. I'll have to try this and see how it compares with fill_from_mesh. 3DS format seems like the logical choice.

      SketchUp Plugins for Professionals

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

        @tig said:

        How about model.selection.add(model.entities.to_a) ?

        I over simplified the example - updated to reflect a purpose.

        Sidenote: . to_a isn't required as selection.add accepts any kind of collection object. It even let you feed it nested array of entities without the need to flatten the array.

        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

          @whaat said:

          I noticed in that thread about adding geometry to the model that someone tried creating the geometry by writing the mesh out to a temporary file format and then importing presumably with the model.import method. I'll have to try this and see how it compares with fill_from_mesh. 3DS format seems like the logical choice.

          I've not tried it. But I got my doubts. Since it seems that it's SU's own processing when adding geometry that causes the slowdown - I'd be surprised if importing geometry suffers from the same slowdowns.

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

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            @thomthom said:

            @tig said:

            How about model.selection.add(model.entities.to_a) ?

            I over simplified the example - updated to reflect a purpose.
            Sidenote: . to_a isn't required as selection.add accepts any kind of collection object. It even let you feed it nested array of entities without the need to flatten the array.

            I usually .to_a my entities, because it stops me falling into trap like modifying the entities whilst referring to them in a loop; or an array is also needed for some other things like entities.transform(tr,entities.to_a)

            TIG

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

              $VERBOSE controls messages and warnings that get set to STDERR.

              Set to nil so SU Ruby doesn't waste time spitting out useless warnings about sloppy code (like "warning: meaningless use of == in nil context") which noone wants to read anyway (when they're doing modelling.) Or my other favorite "warning: parenthesize arguments for future version."

              Settings:
              $VERBOSE = nil : sets 'Silent' mode
              $VERBOSE = false : sets 'Medium' mode (default)
              $VERBOSE = true : sets 'Verbose' mode

              These settings correspond to ruby start parameter -W with values of 0,1,2 (which would also set $VERBOSE in a standard Ruby Environment.)

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • W Offline
                Whaat
                last edited by

                thanks Dan. That will come in handy!

                SketchUp Plugins for Professionals

                1 Reply Last reply Reply Quote 0
                • AdamBA Offline
                  AdamB
                  last edited by

                  I see a lot of SU scripts using some of the more compact iterators Ruby iterators. So they might read nice, but they're often slower than just simple for-loops.

                  shingara.fr

                  This domain may be for sale!

                  favicon

                  (blog.shingara.fr)

                  The other biggie to look out for is operations that involve copying when modifying in place would work just as well. Its slow and it generates lots of garbage.

                  Developer of LightUp Click for website

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

                    @adamb said:

                    I see a lot of SU scripts using some of the more compact iterators Ruby iterators. So they might read nice, but they're often slower than just simple for-loops.

                    shingara.fr

                    This domain may be for sale!

                    favicon

                    (blog.shingara.fr)

                    Interesting. for is faster than each. But do ... end is faster than { ... } ? I really didn't expect that. And I don't see why. Thought it was just alternative syntax. But they behave differently?

                    @adamb said:

                    The other biggie to look out for is operations that involve copying when modifying in place would work just as well. Its slow and it generates lots of garbage.

                    Interesting. I'll have to look through some of my code. I've not thought of that at all.

                    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

                      @thomthom said:

                      But do ... end is faster than { ... } ? I really didn't expect that. And I don't see why. Thought it was just alternative syntax. But they behave differently?

                      hm.. maybe not. seemed to very very little difference. suppose that's other things affecting the minute differences.

                      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

                        And why is for faster then each?

                        Looking at the source code for Array.each:

                        
                        VALUE
                        rb_ary_each(ary)
                            VALUE ary;
                        {
                            long i;
                        
                            for (i=0; i<RARRAY(ary)->len; i++) {
                                rb_yield(RARRAY(ary)->ptr[i]);
                            }
                            return ary;
                        }
                        
                        

                        It's using for as well, and the whole loop is done in C - so why isn't this C for loop faster than a ruby for loop?

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

                        1 Reply Last reply Reply Quote 0
                        • AdamBA Offline
                          AdamB
                          last edited by

                          OT: Any chance the forum administrator of SCF can fix the [ruby] tag to not remove formatting. Formatting is a big part of understanding code, and while for regular text collapsing whitespace down to a single space might work, for code it does not.

                          Developer of LightUp Click for website

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

                            @adamb said:

                            OT: Any chance the forum administrator of SCF can fix the [ruby:38zsi59i]tag to not remove formatting. Formatting is a big part of understanding code, and while for regular text collapsing whitespace down to a single space might work, for code it does not.

                            I think the ruby is meant for inline code. While you got the code tag for block codes. (Though I wish there was a way to expand it - I loathe internal scrollbars.)

                            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

                              Interesting test Adam:

                              doit 6.474 3.292 nil

                              Note: I increased the number of iterations ( 10000000.times { ... })

                              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

                                Didn't realise Ruby would recreate the variables for each iteration. I'd thought it'd keep them for the duration of the loop...

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

                                1 Reply Last reply Reply Quote 0
                                • AdamBA Offline
                                  AdamB
                                  last edited by

                                  Seems an arbitrary (and wrong) assumption that inline code requires removing whitespace. Why not just leave in what the author wrote rather than trying to second guess? Whatever.

                                  Developer of LightUp Click for website

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

                                    Agree - whitespace eating of ruby has bothered me as well. Will ask if it can be changed.

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

                                    1 Reply Last reply Reply Quote 0
                                    • AdamBA Offline
                                      AdamB
                                      last edited by

                                      @thomthom said:

                                      Didn't realise Ruby would recreate the variables for each iteration. I'd thought it'd keep them for the duration of the loop...

                                      The closure you create with curly braces is handled as a first class object and passed as an argument to the iterator. This means the scope of any variables you mention inside that block is limited to that block - it must create them each time. 😞

                                      Developer of LightUp Click for website

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

                                        Is that why each is slow?

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

                                        1 Reply Last reply Reply Quote 0
                                        • GaieusG Offline
                                          Gaieus
                                          last edited by

                                          Guys, Thom asked if we can do something with these white spaces but I have to say it is most probable that we cannot. I is hard coded somewhere in the php script of the forum software and even if we could tweak that, it would be impossible to keep it through upgrades (which is very due soon anyway).

                                          Is the code tag not good (apart from that scrolling annoyance)?

                                          Gai...

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

                                            It's ok. I just hoped there was a config UI for BBCode tags on the forum. Thought it was normal. The code tag is ok, just figured if it could be changed...

                                            I don't suppose there are forum plugins that can be installed? having the code block apply syntax highlighting would be a delight for us coders. Such as this:

                                            http://code.google.com/p/syntaxhighlighter/

                                            http://syntaxhighlighter.googlecode.com/files/Overview01.png

                                            Edit: what version of phpBB does SCF run? I'm looking at this: http://www.phpbb.com/kb/article/adding-custom-bbcodes-in-phpbb3/ from this it appear to be that it'd be a matter of setting the HTML replacement for the ruby tag to not collapse white space using CSS.

                                            Replacement sample something like this:
                                            <span style="white-space:pre;">{TEXT}</span>

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

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

                                            Advertisement