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

Spike: check if you can substitute encoding/json marshalling with a faster json library to remove reflection #12

Open
alessandroargentieri opened this issue Apr 16, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@alessandroargentieri
Copy link
Member

User Story

As a user, I would like to get higher performance for logging.

Detailed Description

Try to substitute classic "encoding/json" marshalling/unmarshalling which uses reflection, with a faster json library (i.e. https://github.com/mailru/easyjson)

@alessandroargentieri alessandroargentieri added the enhancement New feature or request label Apr 16, 2021
@alessandroargentieri
Copy link
Member Author

alessandroargentieri commented Apr 16, 2021

@ilmanzo do you have any suggestions on this?
Do you think is possible to take advantage of other libs or the fact that we don't know the struct of the generic object to be logged prevents us from using a reflectionless library?

@ilmanzo
Copy link
Contributor

ilmanzo commented Apr 16, 2021

I'd suggest first to run profile ( https://blog.golang.org/pprof ) with a sample program that logs many different data structures at different loglevels, to identify the bottlenecks. When I'll find some spare time, I can prepare some benchmarks.

Also take a look at the approach from https://github.com/rs/zerolog (logger developed by Netflix Director of Engineering), because allocation impacts memory footprint and performance (due to pressure on Garbage Collector)

Maybe the user could "tag" the struct fields to decide when to log a field or not, in order to save time and avoid sensitive data leak ?

@alessandroargentieri
Copy link
Member Author

@ilmanzo What is meant by "avoiding allocation"? Do they avoid creating instances of structs in memory? The idea of the tag is very good but only if you know the struct you're going to log. I wanted to cover also the case I make an HTTP request, I get the response and without unmarshalling, I log the response directly, obscurating sensitive data if any. I thought if this is a heavy operation, I could extract the obscuration method outside, so it could be used only if it is explicit. Many thanks for all your precious suggestions.

@alessandroargentieri alessandroargentieri changed the title Substitute encoding/json marshalling with a faster json library to remove reflection Spike: check if you can substitute encoding/json marshalling with a faster json library to remove reflection Apr 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants