Some thoughts on this: > we always tried to load a model bead whether it’s needed or not … > Not all components need a view or a controller or a layout.
I understand this isn’t strictly PAYG but I consider it to be part of UIBase’s lifecycle. One advantage is that MVC (and layout for containers) beads can be injected without changing code. So if, for instance, you want to add a controller that checks permissions and enables or disables a text area accordingly you can do that without changing your code, except to add controller (and possibly a view) that checks for that and acts on your text areas. You can even do that in your css files without having to extend existing classes. > There’s now a function needsView() and needsController() in UIBase. It > defaults to true I think it should stay that way for the reason I stated above. Note that adding this function in UIBase is a PAYG compromise in itself. > not a great way to get a model int he first place because you’re looping > through the beads to find the model every time you access it There was a discussion in the past about making getBeadByType more performant through caching or whatever. I haven’t profiled to see how significant that is though. If type checks are expensive then it probably is. > I changed models to only be loaded the first time it was actually requested. Our implementation is a bit mixed, but the initial design was to assume beads were loaded in a certain order. Beads loaded after model should work on the assumption that it already exists (and has possible been initialized). I would be careful to introduce lazy loading for models for that reason. Thoughts? From: Harbs<mailto:harbs.li...@gmail.com> Sent: Monday, January 3, 2022 1:15 PM To: dev@royale.apache.org<mailto:dev@royale.apache.org> Subject: Bead optimizations I committed some changes to when/how bead lookups work to improve performance. Here’s the details: For the most part, not much has changed from a use-perspective. The only caveat is when it comes to models. We had a type check **every** time a bead was added to check if it was a model bead and we always tried to load a model bead whether it’s needed or not. Needless to say this wasn’t very PAYG. I changed models to only be loaded the first time it was actually requested. Since models don’t actually dispatch events when loaded this is not a problem. The only issue comes up if you use strand.getBeadByType(IBeadModel). This will fail because the model was not added yet. strand.getBeadByType(IBeadModel) is actually not a great way to get a model int he first place because you’re looping through the beads to find the model every time you access it. Since we have a model getter, that’s a much better way to get the model. And with the new change, it’s kind of necessary to do it that way because the getter will load the model if it wasn’t yet loaded. Sometimes components have more than one model. In that case there’s “the” model and other models which is not the main one. It might not be clear to the user which is the main model. To solve that issue, there’s now getModelByType(strand,type) which returns the model and makjes sure it’s initialized if it’s the right type. Otherwise it will find the correct bead and return that. When in doubt, always use this function instead of strand.getBeadByType. Views, Controllers and Layouts had a similar issue to models. Not all components need a view or a controller or a layout. There’s now a function needsView() and needsController() in UIBase. It defaults to true for now because I didn’t want to break things, but subclasses can override and change it to false. This will prevent the view and controller from being loaded. This improves performance on those components. The HTML component set all has this set to false. Similarly, GroupBase now has needsLayout() which also defaults to true and can likewise be overridden to return false. Likewise, the HTML component set sets this to false. HTH, Harbs