Skip to content

Excessive TokenBuffer allocations when deserializing records #5897

Description

@phraktle

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

When deserializing objects whose construction goes through a property-based creator – which includes every Java record, since records always use the canonical constructor – BeanDeserializer._deserializeUsingPropertyBased allocates a fresh TokenBuffer on every call. Each TokenBuffer allocates at least one Segment (an Object[] plus a token-type array). For workloads that stream many small records, this shows up prominently in allocation profiles.

Code path:

  BeanDeserializer.deserialize
    → BeanDeserializerBase.deserializeFromObjectUsingNonDefault
      → BeanDeserializer._deserializeUsingPropertyBased
        → DeserializationContext.bufferForInputBuffering
          → TokenBuffer.forBuffering   // fresh allocation per object

Format-independent — reproduces with JSON, CSV, or any other backend. Since records are now the idiomatic way to model immutable DTOs in Java and unconditionally force this path, users migrating DTOs from classes-with-setters to records see a regression in allocation rate with no change in code shape.

The buffer's lifetime is bounded to _deserializeUsingPropertyBased, so reusing it (with RecyclerPool?) may be feasible.

Version Information

3.1.1

Reproduction

No response

Expected behavior

No response

Additional context

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    performanceIssue related to performance problems or enhancements

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions