Skip to content
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

Binary hooks and HowTo to optimize hot-paths for binary/json encoding #301

Open
jaekwon opened this issue Dec 23, 2019 · 1 comment
Open

Comments

@jaekwon
Copy link
Contributor

jaekwon commented Dec 23, 2019

The easiest way to override amino binary encoding for speed is prob to mirror these json hooks:

// Handle override if a pointer to rv implements json.Unmarshaler.
        if rv.Addr().Type().Implements(jsonUnmarshalerType) {
                err = rv.Addr().Interface().(json.Unmarshaler).UnmarshalJSON(bz)
                return
        }

and

        // Handle override if rv implements json.Marshaler.
        if rv.CanAddr() { // Try pointer first.
                if rv.Addr().Type().Implements(jsonMarshalerType) {
                        err = invokeMarshalJSON(w, rv.Addr())
                        return
                } 
        } else if rv.Type().Implements(jsonMarshalerType) {
                err = invokeMarshalJSON(w, rv)
                return
        }

The binary and json were intentionally written to mirror the code structure, so this kind of translation is easy.

To help keep the convention, please ping me for reviews... there's definitely a lot of value in the way that amino was coded, IMO, so I'd like to preserve that as we keep it as a canonical implementation for go-reflection based proto3 (subset), if anything.

@jaekwon jaekwon changed the title HowTo to optimize hot-paths for binary/json encoding Binary hooks and HowTo to optimize hot-paths for binary/json encoding Dec 23, 2019
@jaekwon
Copy link
Contributor Author

jaekwon commented Dec 23, 2019

Also, it may help to also include thin (non-reflection-based, but o.(interface) direct Go based) optimization in the top-level amino.go files. But we should only add lines of code here for proven needs, such that the code itself can act as a standard.

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

No branches or pull requests

1 participant