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

[core] optimize template rendering #1479

Merged
merged 5 commits into from
Jul 11, 2024

Conversation

cyrilou242
Copy link
Collaborator

@cyrilou242 cyrilou242 commented Jul 11, 2024

Before:

Benchmark                                  Mode  Cnt     Score    Error  Units
StringTemplateUtilsBenchmark.applyContext  avgt    7  1480.610 ± 56.571  us/op

after:

Benchmark                                  Mode  Cnt   Score   Error  Units
StringTemplateUtilsBenchmark.applyContext  avgt    7  55.539 ± 0.272  us/op

Problem: StringTemplateUtils#applyContext - the method to apply properties to template - was extremely slow.
An ObjectMapper was instantiated at each call, so the ser/deserializer obtained by reflection (slow) were re-computed each time.
Optimization: re-use the ObjectMapper. It's a bit tricky because we use custom ser/deser to inject values. Values change at each call.
So we mutate the custom ser/deserializer of the re-used ObjectMapper at each call. This is not thread safe so we introduce a pool of re-usable ObjectMappers.

For an alert with 1000 enumeration items:

  • before: applying properties takes ~ 1000 *1480us ~= 1.5 seconds --> feels to slow in the UI
  • after: applying properties takes ~ 1000 *55us ~= 50 milliseconds

@cyrilou242 cyrilou242 changed the title wip optimize template rendering [core] optimize template rendering Jul 11, 2024
@cyrilou242 cyrilou242 merged commit a9fb04b into master Jul 11, 2024
6 checks passed
@cyrilou242 cyrilou242 deleted the te-2368-optimize-template-rendering branch July 11, 2024 15:49
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.

None yet

1 participant