apache / apache/pulsar

[Enhancement] Cache Schema instances for classes in a weak reference cache since creating an instance could be CPU intensive

Open
#23,707 1 comment 0 reactions 0 assignees View on GitHub
type/enhancement
Dominant language
Java
Stars
15.3k
Forks
3.8k
Avg merge
1d 14h
Merged PRs (30d)
160

Description

### Search before asking

- [X] I searched in the [issues](https://github.com/apache/pulsar/issues) and found nothing similar.

### Motivation

For example, `Schema.AVRO(SomeClass.class)` is fairly CPU intensive. It would be useful it there would be a weak reference cache for caching the schema instance.

### Solution

* add a weak reference cache for caching a scheme instance for Schema.AVRO, Schema.JSON, Schema.PROTOBUF.
* Don't return the schema instance directly since schema instances are mutable. Instead return a clone of the cached instance.

### Alternatives

-

### Anything else?

-

### Are you willing to submit a PR?

- [ ] I'm willing to submit a PR!

Contributor guide

Open the contributing guide

Research direction

Start at the Schema.AVRO, Schema.JSON, and Schema.PROTOBUF entry points and trace how schema instances are created. Define completion around weakly caching those instances while returning clones so callers cannot mutate the cached objects; verify the behavior with the relevant existing schema tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.