Concrete struct (defined as CONCRETE and *_rep) is used as reference counter. For example, type T is implemented as two class: T_rep handles properties of given type, and T handles reference and counter of references to T_rep. When T is assigned, only reference is assigned with counter in/decreased.
std::shared_ptr plays a similar role like concrete struct, and maintain a spin lock on reference count, thus avoid data-race in parallel execution environments. However, the spin lock drags performance down when code is executed in a single thread serially.
Works
rewrite string with shared_ptr
add standard allocator for shared_ptr
Performance
Table below shows performance measured by string_bench.
Motivation
Concrete struct (defined as
CONCRETE
and*_rep
) is used as reference counter. For example, typeT
is implemented as two class:T_rep
handles properties of given type, andT
handles reference and counter of references toT_rep
. WhenT
is assigned, only reference is assigned with counter in/decreased.std::shared_ptr
plays a similar role like concrete struct, and maintain a spin lock on reference count, thus avoid data-race in parallel execution environments. However, the spin lock drags performance down when code is executed in a single thread serially.Works
string
withshared_ptr
shared_ptr
Performance
Table below shows performance measured by
string_bench
.Before
construct string
equality of string
compare string
slice string
concat string
append string
is quoted
After
construct string
equality of string
compare string
slice string
concat string
append string
is quoted