Comments (3)
Maybe--I'd love to see benchmarks.
Note that built_value
is already optimized so that updating a deeply nested structure of objects is O(length of path from modification to root), and not O(size of data structure).
from built_collection.dart.
Thanks John. Indeed, the idea was to keep the possibility of using such data structures open.
One reason we haven't looked at it yet is we don't really have a good use case to benchmark with.
The "addItem" example might look like a problem, but so far it's always been in UI code where adding an item corresponds to a click and subsequent redraw. In that case the rendering time is likely to be far higher than the list copy, so it's not a big concern. For larger updates that are caused by a single click, you're supposed to use builders rather than repeatedly rebuilding.
One other direction that might be worth exploring is based on the idea that in the most common use of 'rebuild', the original list may not ever be used again. So for "addItem" we could do this instead:
- update the old BuiltList to say "I'm the new BuiltList minus the last item"; this is expensive if it's used, but we assume it probably won't be
- create the new BuiltList by stealing the underlying list from the first and adding the item
Then, if the old list is never used again, we do nothing extra, and it's almost as fast as a mutable list to update, and as fast as a mutable list for reading. If the old list is used again then extra work is needed to either implement the list interface over a "BuiltList minus last item", or we just copy the underlying list and actually remove the last item.
In order to pursue this line of thought we'd also need a good use case to benchmark with.
So, bottom line is, let's find some code that actually wants fast immutable data structures :) and then, yes, please do go ahead and prototype something, I'd love to see it.
from built_collection.dart.
What about use cases like flutter_redux? Things like HAMT would be quite helpful when one want to update/diff a large amount of data between Flutter frames.
from built_collection.dart.
Related Issues (20)
- Release for inference change HOT 1
- Add const BuiltList<T>.empty() HOT 6
- Add ListBuilder.indexOf HOT 1
- Allow BuiltList<T?> HOT 2
- BuiltList first & elementAt should be nullable HOT 3
- Custom serializer for BuiltMap HOT 1
- Tighten generics HOT 2
- Use `@checkResult` annotation
- Cannot rebuild a BuiltSet entry in BuiltMap HOT 7
- (Question) how to rebuild every value in BuiltList? HOT 1
- Why is the return operator[] on BuiltSetMultimap nullable?
- Docs for `asList` misleading
- Unable to update nested BuiltList inside ListBuilder HOT 5
- [Feature Request/ Question] Native Support for json_serializable / json_annotation HOT 3
- Found 1 file excluded from sound null safety HOT 1
- Shouldn't BuiltMap<String, BuiltSet<int>> work out of the box? HOT 9
- BuiltMap.containsKey should accept `Object?` HOT 1
- Built Collections deep comparison question HOT 3
- asList() always returns a new instance HOT 1
- tighten `MapBuilder` factory parameter HOT 2
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 built_collection.dart.