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

perf(orca): reuse ObjectMapper instances #2937

Merged
merged 3 commits into from
May 30, 2019

Conversation

mattnworb
Copy link
Contributor

@mattnworb mattnworb commented May 24, 2019

creating a new ObjectMapper instance for each Stage or other per-request
contexts can be wasteful; ObjectMapper is safe to reuse across threads
(after it is configured). See spinnaker/spinnaker#4367 for more details.

creating a new ObjectMapper instance for each Stage or other per-request
contexts can be wasteful; ObjectMapper is safe to reuse across threads
(after it is configured). See
spinnaker/spinnaker#4367 for more details.
Copy link
Contributor

@jtk54 jtk54 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Contributor

@ezimanyi ezimanyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable to me, but would like @robzienert or @robfletcher to take a look as I know that there have been some subtle bugs with objectMapper in the past.

@robfletcher
Copy link
Contributor

Are there any places where the ObjectMapper is customized for particular use cases? Just wondering why we had it as a factory in the first place.

Copy link
Member

@robzienert robzienert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be fine. 99... 95... 96.7% sure.

@mattnworb
Copy link
Contributor Author

@robzienert I did find a few places in the Orca codebase where the new ObjectMapper instance returned by OrcaObjectMapper.newInstance() is mutated / configured in different ways:

val mapper = OrcaObjectMapper
.newInstance()
.setPropertyNamingStrategy(
PropertyNamingStrategy.SNAKE_CASE)
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) // we want Instant serialized as ISO string

@Bean fun keelObjectMapper() =
OrcaObjectMapper.newInstance()
.registerModule(KotlinModule())
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
}

val mapper = OrcaObjectMapper
.newInstance()
.disable(WRITE_DATES_AS_TIMESTAMPS) // we want Instant serialized as ISO string

I left all of those unchanged in this PR, since from what I could tell, those call sites were not creating one ObjectMapper per request / unit of work etc. (and plus they seem to have legitimate reasons to configure the ObjectMapper instance differently than other regions of code).

@ezimanyi ezimanyi merged commit 8835c07 into spinnaker:master May 30, 2019
robzienert pushed a commit to robzienert/orca that referenced this pull request May 31, 2019
creating a new ObjectMapper instance for each Stage or other per-request
contexts can be wasteful; ObjectMapper is safe to reuse across threads
(after it is configured). See
spinnaker/spinnaker#4367 for more details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants