[Enhancement] Cache Schema instances for classes in a weak reference cache since creating an instance could be CPU intensive
- 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
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