You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Optimize Thrift-Python Map Conversion: Lazy Access values for String/Primitive Keys
Summary:
**Overview**
The diff implements a lazy conversion optimization for Thrift maps, deferring the type conversion of map values until they are actually accessed. This approach covers over **82%** of use cases D85260454 and achieves approximately **30x** performance improvements for random access operations when the map key is [NC|str]
This diff Implements lazy value conversion for map values when key conversion is not required (i.e., keys are of types int, float, str and etc.). In these cases, value conversion is deferred until the value is accessed for the first time.
**Two Internal Storage Fields**
* `_fbthrift_internal_elements`
* Type: `types.MappingProxyType` (read-only dict wrapper)
* Purpose**: Holds the original internal representation before Python type conversion
* When set**: Only when lazy conversion is enabled
* When cleared**: Set to `None` after full conversion is performed
* `_fbthrift_elements`
* Type**: `dict` | `types.MappingProxyType` (read-only dict wrapper)
* Contains**: Python-converted data
* Purpose**: Cache for converted key-value pairs
* Fully populated immediately with all converted data for **"non-lazy"** mode
* Starts as empty `{}`, gradually populated as keys are accessed for **"lazy"** mode.
**Performance Wins:**
**Random Access with `NC` | `String` Keys**: **27-38x faster** (96-97%
improvement)
{F1983317953} {F1983317951}
Reviewed By: ahilger, yoney
Differential Revision: D86317214
fbshipit-source-id: f63252b8919a68858238a2b808469d8e2569a4ef
0 commit comments