question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Zero reflection usage

See original GitHub issue

Reflection is bad because:

  1. it’s really, really slow
  2. it bloats the code size for AOT-only scenarios
  3. it adds the need to add hints/configuration for IL linker in AOT scenarios

I’d like to completely remove reflection usage from Avalonia. We should be able to run with CoreRT without additional .rd.xml files and with these compatibility flags disabled.

Right now our users of reflection are:

  • Portable.Xaml (will be fixed by XamlIl)
  • Bindings (we have compiled bindings now)
  • Style selector parsers (will be fixed by XamlIl)
  • Weak event managers
  • StyleInclude/ResourceInclude
  • DBus
  • AssetsLoader
  • Anything else?

There are two problems with bindings that we need to solve:

  1. If we want to have them compiled, we need to know the type of DataContext in advance. So we might need to add some kind of XAML directive (e. g. DataContextType="{x:Type myNs:MyType}") for specifying the data context type when it can’t be determined from DataType or from binding from the parent DataContext. That would be most likely required for top-level XAML element only.
  2. We have IStreamPlugin extension point which isn’t strongly typed and is resolved in runtime. We need to make it to somehow work at compile time.

While we are working on these, new features get added, so when adding a new feature that needs type information, provide a way for it to work at compile time.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:30
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

5reactions
kekekekscommented, May 12, 2020

@Mrxx99 we aren’t planning to drop F# support. Source generators will be used for generating fields for x:Name, however.

5reactions
aelijcommented, Mar 19, 2019

I think implementing compile-time bindings would be great. I had some experience lately with x:Bind in UWP and while it has its issues, it’s very appealing. It also significantly reduces the need for converters, as the binding expression is converted to a C# method, and so can include method calls, casts, etc.

The data context problem was solved by changing the binding context to the class the XAML file is attached to, and you’d usually have one or more strongly-typed properties in it (e.g. ViewModel), instead of the DataContext. For DataTemplates, the DataType is used.

Code is generated at design/compile time. I’m not sure if MS intends on open-sourcing the x:Bind implementation (it’s a part of the XAML MSBuild tasks, but only in UWP.) Perhaps it’s worth asking.

Read more comments on GitHub >

github_iconTop Results From Across the Web

reflect.Zero() Function in Golang with Examples
The reflect.Zero() Function in Golang is used to get the Value representing the zero value for the specified type. To access this function,...
Read more >
reflect package
The typical use is to take a value with static type interface{} and ... Zero takes a Type and returns a Value representing...
Read more >
java - What is reflection and why is it useful?
The name reflection is used to describe code which is able to inspect other code in the same system (or itself). For example,...
Read more >
Reflection in Go: Everything you need to know to use it ...
Reflection in Go allows you to examine and manipulate variables and types while your program is running. This means that you can check...
Read more >
Is it a bad habit to (over)use reflection?
Basically, avoid reflection in general code if at all possible; look for an improved design. Share.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found