Skip to content

Conversation

@akuzni2
Copy link
Contributor

@akuzni2 akuzni2 commented Dec 5, 2025

Summary

Add ChannelDefinitionOptsCache to optimize access to ReportCodec options especially in outcome and reporting.

Current usage of ChannelDefinition Opts requires parsing Opts from JSON Bytes -> struct which has an impact on performance with many channels.

See the added bechmark test for performance gain of switching to cache approach.

  • 40-50x improvement of using the Cache + type assertion over direct JSON parsing.

Cache Design and Usage

The design of the cache needed to work with varying types of Opts as each ReportCodec manages it's own Opts struct. Therefore what the cache stores is a generic type any which is faster to type assert than it is to re-parse from JSON bytes.

Where we need to access Opts - we can expose a new OptsProvider and each codec that we'd like information from can Implement it such as TimeResolutionProvider or ABIProvider or SomeOtherUniqueOptProvider. Not all codecs need implement these interfaces which is good interface segregation.

Interface Change

Noting that interface was changed ReportCodec.Encode()

  • Added parsedOpts interface{} parameter
    • Codecs check if non-nil and use cached value, otherwise fall back to parsing cd.Opts

This was chosen as it's easier at the call site when encoding with various possibilities of ReportCodecs to use the pattern of:

  • opts := optsCache.Get(channelId)
  • report Encode(report, opts)

@akuzni2 akuzni2 changed the title DS-1732 channel opts cache DS-1732 channel definition opts cache Dec 5, 2025
@akuzni2 akuzni2 marked this pull request as ready for review December 5, 2025 03:20
@akuzni2 akuzni2 requested a review from a team as a code owner December 5, 2025 03:20
@akuzni2 akuzni2 requested a review from brunotm December 9, 2025 04:00
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.

2 participants