diff options
author | Peter Zhu <[email protected]> | 2023-11-20 11:28:36 -0500 |
---|---|---|
committer | Peter Zhu <[email protected]> | 2023-11-20 18:59:01 -0500 |
commit | a182b2c5e1dbdbe8960912f8bac076d997a74e65 () | |
tree | e19ac316b7c4a36f4be9560d72de6b28c9a49b21 | |
parent | ad033207435b8e18f12c70643afbf68725948230 (diff) |
Implement Enumerator objects on VWA
This commit implements Enumerator objects on VWA. This speeds allocations and decreases memory usage. ``` require "benchmark" ary = [] puts(Benchmark.measure do 10_000_000.times do u = ary.to_enum end end) puts `ps -o rss= -p #{$$}` ``` Before: ``` 1.500774 0.002717 1.503491 ( 1.506791) 18512 ``` After: ``` 0.892580 0.002539 0.895119 ( 0.897642) 16480 ```
-rw-r--r-- | enumerator.c | 16 |
1 files changed, 4 insertions, 12 deletions
@@ -256,23 +256,15 @@ struct enum_product { VALUE rb_cArithSeq; -#define enumerator_free RUBY_TYPED_DEFAULT_FREE - -static size_t -enumerator_memsize(const void *p) -{ - return sizeof(struct enumerator); -} - static const rb_data_type_t enumerator_data_type = { "enumerator", { REFS_LIST_PTR(enumerator_refs), - enumerator_free, - enumerator_memsize, NULL, }, - 0, NULL, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_DECL_MARKING }; static struct enumerator * @@ -1909,7 +1901,7 @@ lazy_add_method(VALUE obj, int argc, VALUE *argv, VALUE args, VALUE memo, rb_ary_push(new_procs, entry_obj); new_obj = enumerator_init_copy(enumerator_allocate(rb_cLazy), obj); - new_e = DATA_PTR(new_obj); new_e->obj = new_generator; new_e->procs = new_procs; |