You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@thrift.apache.org by "Dmytro Shteflyuk (Jira)" <ji...@apache.org> on 2026/10/23 00:49:00 UTC

[jira] [Created] (THRIFT-6449) Reduce allocations during Ruby recursive type checking

Dmytro Shteflyuk created THRIFT-6449:
----------------------------------------

             Summary: Reduce allocations during Ruby recursive type checking
                 Key: THRIFT-6449
                 URL: https://issues.apache.org/jira/browse/THRIFT-6449
             Project: Thrift
          Issue Type: Bug
          Components: Ruby - Library
            Reporter: Dmytro Shteflyuk
            Assignee: Dmytro Shteflyuk


h3. Problem

Thrift.check_type constructs a temporary class array for every checked value and a diagnostic path string for every collection element, including values that pass validation.

h3. Client impact

Applications that enable optional Ruby type checking incur allocation and garbage-collection overhead when validating large lists, sets and maps. Type checking is disabled by default.

h3. Reproduction

From the repository root, using CRuby 4.0.7:

{code:language=bash}
ruby -Ilib/rb/lib -rthrift/types <<'RUBY'
values = Array.new(250_000, 42)
field = {type: Thrift::Types::LIST, element: {type: Thrift::Types::I32}}
Thrift.check_type(values, field, :values)
GC.start
before = GC.stat(:total_allocated_objects)
Thrift.check_type(values, field, :values)
puts GC.stat(:total_allocated_objects) - before
RUBY
{code}

Testing on master commit {{50b43e6598ec87f27587108d0ef4a7c91cc1bced}} produces:

{code}
500003
{code}

This counts allocations during one validation of 250,000 valid integers, after warming up the validator. Exact counts may vary with the Ruby version.

h3. Expected behavior

Successful recursive type checks should avoid constructing class arrays and diagnostic strings for every scalar element. Preserve recursive validation, nil handling, subclass acceptance, exact declared struct-class checks and diagnostic paths.




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)