-
Notifications
You must be signed in to change notification settings - Fork 515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose [NS|UI]View.Subviews with NSArray variant #5325
Comments
It's both a general [1] problem (calling multiple time the same property without realizing its cost [2]) and a matter of discoverability of the alternative/better API, i.e. if you know there's a problem it's easy to work around. E.g.
That still has an extra cost (over Note that I'm not against adding a
would be quite bad. [1] same for |
Yup, it depends on the use-case. Having both NSArray and Array bindings would allow the user to choose the better trade-off (gc vs cpu per loop iteration). |
This improvement is absolutely needed across the entire API surface of XI/XM. By applying the same technique to |
Impressive! I'm glad the discussion helped :) Now we cannot fix the existing API without breaking changes. The right approach would be to drop managed arrays and instead expose It's a bit more complex than just properties since every API that accept managed arrays would also need to be updated to use In theory we could expose additional |
This would be a source-code breaking change, so I do not support it on a XAMCORE_4 world. As discussed on chat if you end up looping over all the values in the array, you will be faster using the marshaling we provide than going through NSArray wrappers to fetch the values. And in fact, for Aaron's use case, by hoisting the access to those arrays out of the loop, he got his performance back as he was using that idiom. For the scenarios where this does not work, we should explore adding an additional helper method (side-by-side) that could provide access to that method, maybe on a separate namespace as an extension method, so you could do "using UIKit.NSArrayAPI" and then be able to call "NSArray UIKit.GetSubViews ()" method on it. |
I think it would be better, for discoverability, to have them as side-by-side methods which expose the NSArray, rather than an array. Having it in a different namespace does reduce pollution in the completion list by default, but I'd prefer discoverability over verbosity of a completion list (I think we won't have more than 4 matches in the list when writing |
Another thing to note is that something is busted when using Sometimes, when iterating the
The solution was to use |
@Therzok please file a bug w/test case about the later - it should not throw. |
This is an advanced feature - I rather document how to have an idiom for users of the advanced API than have to explain the difference in the base api. |
Steps to Reproduce
Expected Behavior
We should have an API endpoint that exposes an NSArray.
Actual Behavior
There is none.
Notes
Scenario:
The above code would marshal the array twice, every time we iterate. Also, array length queries would have to marshal the array to managed, so simply doing:
Having an NSArray based overload would avoid that and help for performance with multiple subviews in the NSView.
The text was updated successfully, but these errors were encountered: