In one of our apps, a lot of controls are used which get updated and we saw in our speed measurements that a significant time is spend into finding controls.
Yes, each access to a control triggers a call to Window._ControlByName which finds the control based on the name.
The point is to avoid the lookup at all by using real properties.
if I need controls via name, I can lookup them myself, but when I write something like label1.text =t, I don’t want a function to run. Just a label1 property with the reference to the control.
dont refetch the reference every time - a common optimization
change your code in PushButton1.action to
#Pragma DisableBackgroundTasks
dim m1 as Double = Microseconds
Dim tmp As label = label1
for i as integer = 1 to 1000000
dim b as Boolean = tmp.Enabled
next
dim m2 as Double = Microseconds
dim md as Double = m2-m1
MsgBox str(md)+" Microseconds"
and its even faster than the property version in PushButton2.action since locals are quicker to access than properties
Making things properties is not the panacea you imagine and has a lot of complexities
This code is to test and benchmark the difference (see my test project which looks similar).
In the real project, this may be a method which accesses e.g. 500 properties of 100 controls and each time the control is looked up by name. I’d really like to get away with that overhead.
I get that
My recommendation is a common optimization technique used all over that is even faster and requires NO changes to the framework IDE etc etc etc
Hold the reference in a local and use the local
Then you look each control up ONCE rather than 500 times for each property
THAT you can do today with no huge overhauls of the IDE or the frameworks
Making controls properties is NOT the panacea you imagine it will be
There are LOTs of details that have to be looked after otherwise we break lots of projects silently
For instance these properties can’t be hard references because you CAN close a control on a layout that was placed there at design time.
So we have to use something like a WEAK REF and that means there’s still a method or something that has to exist to cast that to the right type.
And there are of course LOTS of details like this