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

Cleanup codec usage #2563

Merged
merged 11 commits into from
Dec 29, 2023
Merged

Cleanup codec usage #2563

merged 11 commits into from
Dec 29, 2023

Conversation

StephenButtolph
Copy link
Contributor

@StephenButtolph StephenButtolph commented Dec 29, 2023

Why this should be merged

This standardizes how we use the reflect codec and simplifies some code paths.

How this works

It's essentially a pure refactor.

How this was tested

  • CI

@StephenButtolph StephenButtolph self-assigned this Dec 29, 2023
)

var c codec.Manager
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Codec is much easier to read than c and this allows easier usage of the format.

Comment on lines +11 to +22
const CodecVersion = 0

var Codec codec.Manager

func init() {
lc := linearcodec.NewDefault()
Codec = codec.NewDefaultManager()

if err := Codec.RegisterCodec(CodecVersion, lc); err != nil {
panic(err)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was no reason we created a new codec for each encdb instance.

Comment on lines +13 to +24
const CodecVersion = 0

var Codec codec.Manager

func init() {
lc := linearcodec.NewCustomMaxLength(math.MaxUint32)
Codec = codec.NewManager(math.MaxInt)

if err := Codec.RegisterCodec(CodecVersion, lc); err != nil {
panic(err)
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was no reason we created a new codec for each indexer.


func init() {
lc := linearcodec.NewCustomMaxLength(math.MaxUint32)
Codec = codec.NewManager(math.MaxInt)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There was no reason to have a complex calculated maximum length here.


func init() {
lc := linearcodec.New([]string{reflectcodec.DefaultTagName + "V0"}, maxSize)
lc2 := linearcodec.New([]string{reflectcodec.DefaultTagName + "V1"}, maxSize)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

lc2 seemed very confusing here... because this is version 1.


c = codec.NewManager(maxSize)
// for backward compatibility, still register the initial codec version
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't really for backwards compatibility... I think this was a remnant of a prior design for the stop vertex codec handling.

@StephenButtolph StephenButtolph added the cleanup Code quality improvement label Dec 29, 2023
@StephenButtolph StephenButtolph added this to the v1.10.18 milestone Dec 29, 2023
@StephenButtolph StephenButtolph marked this pull request as ready for review December 29, 2023 18:46
@StephenButtolph StephenButtolph added this pull request to the merge queue Dec 29, 2023
Merged via the queue into dev with commit e89d972 Dec 29, 2023
17 checks passed
@StephenButtolph StephenButtolph deleted the cleanup-codec-usage branch December 29, 2023 21:31
pull bot pushed a commit to AKAJOKER2/avalanchego that referenced this pull request Jan 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code quality improvement
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants