-
Notifications
You must be signed in to change notification settings - Fork 855
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
Use freezable pattern for contract types instead of deep cloning #179
Comments
Another proposal is to use C# 9 record types so the config objects are always immutable after creation. Known issues:
|
Note today we make some costly deep clones of many objects to avoid anyone mutating them while we're using them. reverse-proxy/src/ReverseProxy/Abstractions/ClusterDiscovery/Contract/Cluster.cs Lines 59 to 72 in e4426b9
|
What should we add or change to make your life better?
Currently, we are making deep clones of all
Abstractions.*.Contract
types' instances (e.g.LoadBalancingOptions
orQuotaOptions
) before adding them to repositories. On top of that, some of them even have duplicates inRuntimeModel
namespace with exactly the same contract, but different names (e.g.LoadBalancingOptions
andBackendConfig.BackendLoadBalancingOptions
). This is done to ensure safety and consistency of concurrent configuration reads in requests handling as well as to avoid accidental modifications.However, it leads to code duplication and extra allocations in runtime. Thus, it's proposed to get rid of deep cloning and make all
Abstractions.*.Contract
types freezable which means they will be mutable during configuration initialization or refresh, but will prohibit any state changes after aFreeze()
method is called. Each top-most configuration type (e.g.Backend
andRoute
) will freeze it's state on aFreeze()
call and ensure that all nested instances do the same (i.e.Backend.Freeze()
must also callLoadBalancingOptions.Freeze()
). Further,ProxyConfigLoader
will callFreeze()
on all top-most instances before adding them into repositories.Why is this important to you?
It will eliminate code duplication, the reduce number of allocations and memory footprint.
The text was updated successfully, but these errors were encountered: