Comments (3)
Yes, I've wanted that as well. This project already offers this, but in a slightly different way that produces much less GC pressure: it uses structs for the red tree. This comes with some trade-offs (e.g. no automatic polymorphism) but we use the code generation to make conversion between types super easy. You can check out the ProjectTree tests that demonstrate this.
What do you think?
At the time I wrote this feature, I talked to the Roslyn folks about it. They mentioned they had (IIRC) 3 different varieties of red/green trees, and this was one of them. Again IIRC, they chose to have 3 varieties both because of evolution of thought and because they each have their own pros/cons so different answers apply to unique scenarios.
from immutableobjectgraph.
Ok, so if I'm following this all ancestor access is relative a common ancestor or "root". Rooting a node makes that node the common ancestor "embedding" it so that you can traverse down and back up without having to maintain a reference to the root. But traversing the ancestors is computationally "heavy" as it either descends the tree from the root or uses the roots look-up table. To reduce the computational load you probably want to scope operations by Rooting at an appropriate level in the tree to avoid scanning a huge tree if you only need to manage a small scope. You use WithRoot to move the scope back to a broader or original root scope. Any time a rooted node is mutated the "Red" spine is rebuilt for you so you don't have to manage the unzip/rezip of the ancestors. You can then use the Root property to get to the new root. You can move back and forth between rooted and un-rooted depending on the operations you are performing and how you want them to affect the tree. This requires that the developer have a pretty solid grasp on the impact of operations in these two modes to get the best performance and use out of the pattern. Probably a steep learning curve for the average .NET developer. Is my assessment of this implementation correct?
from immutableobjectgraph.
That sounds about right. Except I wouldn't typically worry to operate at a smaller scope (i.e. subtree). The full tree's lookup dictionary should be allowed to be built up, and is purged incrementally (IIRC) as you modify the tree, just like a sub-tree would. Except that by operating at the full tree, when you're done, the cache is already built up.
There are of course cases where you can make things extremely efficient by working from leaf to root, for example, even before you attach the Rooted structure. But I would make such optimizations only when you have a pretty good idea that it will matter.
from immutableobjectgraph.
Related Issues (20)
- Fix test failures HOT 1
- Emit PureAttribute on all pure members HOT 1
- Analyzer to flag invocations of [Pure] methods as an ExpressionStatementSyntax HOT 2
- Self-referencing collections shouldn't have to have "using IOG;"
- Implement IEqualityComparer<T> for immutable types
- `DefineWithMethodsPerProperty = true` fails when source doc has no using for ImmutableObjectGraph
- Empty/IsEmpty properties HOT 7
- Implement Visitor pattern for Walkers and Re-writers
- Trying to upgrade from 1.1.7 HOT 7
- Document if capable generating readonly struct HOT 2
- Build fails once .NET Core SDK 3 is installed HOT 1
- Missing using ImmutableObjectGraph when model has ImmutableList<T> fields HOT 1
- Can I target .NET FW 4.5 HOT 1
- Property-specific With methods fail when using `ReadOnlyMemory<byte>` fields
- Use <inheritdoc> in many more places to get docs copied
- .Net Core support HOT 1
- Use in .Net Core project HOT 2
- Cannot compile with Visual Studio 2017 HOT 8
- Adding deconstruction
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from immutableobjectgraph.