Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dmjio
Copy link
Owner

@dmjio dmjio commented Dec 5, 2025

Currently, decoding events uses aeson. This works by converting the entire JS object structure into Value. This incurs significant allocation overhead. Events are high frequency and minimizing allocations is important.

This PR introduces an Event parser (Parser a) that bypasses the conversion into Value by performing parsing in JSM directly on the raw JSVal (FFI.Event object).

This works by replacing the FromJSON constraint in favor of the more efficient FromJSVal and parsing in an ExceptT, with two error cases.

We expose a FromJSON-like interface for end users. The code stays the same, but

  • Define and expose withObject, (.:)
  • Adds SyntheticEvent nomenclature.
  • Adds executeDecoder helper
  • Adds various FromJSVal instances.

This opens up the door for more aeson-combinators like (.:?), (.!=), etc.

  • .:?, .!= added

Currently, decoding events uses `aeson`. This works by converting the
entire JS object structure into `Value`. This incurs significant
allocation overhead. Events are high frequency and minimizing allocations is
important.

This PR introduces an `Event` parser (`Parser a`) that bypasses the conversion
into `Value` by performing parsing in `JSM` directly on the raw
`JSVal` (`FFI.Event` object).

This works by replacing the `FromJSON` constraint in favor of the more
efficient `FromJSVal` and parsing in an `ExceptT`, with two error
cases.

We expose a `FromJSON`-like interface for end users. The code stays
the same, but

- [x] Define and expose `withObject`, `(.:)`
- [x] Adds `SyntheticEvent` nomenclature.
- [x] Adds `executeDecoder` helper
- [x] Adds various `FromJSVal` instances.

This opens up the door for more aeson-combinators like `(.:?)`,
`(.!=)`, etc.
@dmjio dmjio mentioned this pull request Dec 5, 2025
4 tasks
@dmjio dmjio marked this pull request as draft December 7, 2025 09:53
@dmjio
Copy link
Owner Author

dmjio commented Dec 11, 2025

Make sure this is tested on the JS backend, w/ WASM it might be slower because it uses Text for everything since its using jsaddle command protocol and not raw FFI backend.

@dmjio dmjio mentioned this pull request Dec 11, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants