Comments (5)
I don't think plain objects is the right answer because they still need to undergo JSON encoding. It'll be faster, since it's C code instead of JS-hosted Kotlin code, but it's still JSON encoding.
We can instead teach each Change
subtype to JSON "encode" itself directly to a string and build up the JSON in a buildString
directly, only calling out to kotlinx.serialization for user types like you said.
I mean look at what we generate:
The Create
class can get a member
public fun appendJsonTo(builder: StringBuilder) {
builder.append("""["create",{"id":""")
builder.append(id.value)
builder.append(""","tag":""")
builder.append(tag.value)
builder.append("}]")
}
and we're done. Repeat for all the other subtypes.
Then with a custom serializer for List<Change>
we can do the top-level buildString
+ comma insertion, and then write that as an unsafe raw string into the JsonEncoder
.
An even more efficient version of this bypasses allocating any Change
instances and simply builds the raw JSON string directly. Unfortunately this breaks the current API unless we do something crazy like
class RawJsonChange : Change {
val json = StringBuidler()
}
and only have this single allocation per set of changes.
from redwood.
Doing JSON encoding in JS would be more efficient if we had a good StringBuilder on QuickJS. Sigh.
from redwood.
True. We could do a List and write them all sequentially to the underlying stream.
from redwood.
I used a sampling profiler to measure just how much time we’re spending in serialization code. For one sample I took it’s about 19% of the samples:
With this optimization implemented that drops down to about 3% of the samples:
from redwood.
Is this done?
from redwood.
Related Issues (20)
- Support for Widget.dispose() for non-protocol applications
- Add layout direction variation to iOS snapshot tests
- `CrossAxisAlignment.Start` forces child to wrap its size on Android
- Turn off Zipline API tracking for test app
- Ship a BOM
- Close TreehouseDispatchers in TreehouseApp.Factory.close() HOT 2
- Support unsetting of unscoped modifiers
- Remove code dealing with old memory model
- Changes to `Modifier.size` are not reflected HOT 2
- Consider splitting the binding for scrolling vs. non-scrolling layouts.
- Root component’s dimensions inconsistent across platforms HOT 1
- Please add a Default EventListener HOT 2
- Treehouse Gradle Plugin
- IndexOutOfBoundsException in LazyListUpdateProcessor HOT 1
- Protocol does JSON decoding on the main thread
- Determine if density multiplier still should exist
- UncaughtTreehouseException: toIndex = 1
- Use a Redwood schema for loading and error UIs HOT 6
- [jwilson] use this once we update Zipline. HOT 1
- Once QuickJS supports WeakRef, enable regular tests:
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 redwood.