Should we be autoloading?
-
Just thinking out loud here...
Since the SketchUp Ruby API environment is a shared one - would it not be best practice for us (developers) to use
autoloadinstead ofrequire?This would not be feasible with scrambled ruby files as they rely on
Sketchup::require- but for all the unscrambled ruby files. The majority is unscrambled. And users have many many plugins installed - often they will use only a fraction of them.I'm not expecting a major memory benefit - but I do think that we could expect improvement in SketchUp startup times.
(Sidenote - I do suspect that toolbar creation is a major component in the startup time. Something that ought to be investigated.)
Fire at will!
-
That sounds interesting.
It's not "thread safe" but I don't think that matters for us.
Symbols don't support colons, so nested modules would be done like in the comments here: http://www.rubyinside.com/ruby-techniques-revealed-autoload-1652.htmlHow much would be the performance gain?
One could do some testing (I'll do this evening) like plugins normal, plugins disabled, plugins with autoload. -
I remember trying this a long time ago.. but did not get it working. Maybe I used it wrong?
As I remember it loads modules, not scripts. So perhaps the name of the script must be the same as the module ?
-
@dan rathbun said:
I remember trying this a long time ago.. but did not get it working. Maybe I used it wrong?
I do have it working for a large project I'm working on. I set up some of the mixing modules and base classes to autoload.
<span class="syntaxdefault"><br /> </span><span class="syntaxcomment"># Ensure abstract classes are loaded and found when needed.<br /> </span><span class="syntaxdefault">autoload</span><span class="syntaxkeyword">( ;</span><span class="syntaxdefault">Observable</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">PATH</span><span class="syntaxkeyword">, </span><span class="syntaxstring">'observable.rb' </span><span class="syntaxkeyword">) )<br /> </span><span class="syntaxdefault">autoload</span><span class="syntaxkeyword">( ;</span><span class="syntaxdefault">BezierEntity</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">PATH</span><span class="syntaxkeyword">, </span><span class="syntaxstring">'bezier_entity.rb' </span><span class="syntaxkeyword">) )<br /> </span><span class="syntaxdefault">autoload</span><span class="syntaxkeyword">( ;</span><span class="syntaxdefault">BezierPatch</span><span class="syntaxkeyword">, </span><span class="syntaxdefault">File</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">join</span><span class="syntaxkeyword">( </span><span class="syntaxdefault">PATH</span><span class="syntaxkeyword">, </span><span class="syntaxstring">'bezier_patch.rb' </span><span class="syntaxkeyword">) )<br /> </span><span class="syntaxdefault"></span>
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement