diff options
| author | Scott Shawcroft <scott@tannewt.org> | 2018-06-28 10:43:39 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott@tannewt.org> | 2018-07-03 05:45:51 -0700 |
| commit | cced51cbd23aa732f0243fe555b4427ff46267b4 (patch) | |
| tree | 17c2b2d3a9b1869602975e269e2e0dd4a361c052 /py | |
| parent | 9de611c056e06684dfa9e5fb4c5fd2f4df579046 (diff) | |
Limit qstr pool size to reduce memory waste.
Diffstat (limited to 'py')
| -rwxr-xr-x[-rw-r--r--] | py/mpconfig.h | 6 | ||||
| -rwxr-xr-x[-rw-r--r--] | py/qstr.c | 10 |
2 files changed, 13 insertions, 3 deletions
diff --git a/py/mpconfig.h b/py/mpconfig.h index 765ae1e8f..74d7c2c92 100644..100755 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -130,6 +130,12 @@ #define MICROPY_ALLOC_QSTR_CHUNK_INIT (128) #endif +// Max number of entries in newly allocated QSTR pools. Smaller numbers may make QSTR lookups +// slightly slower but reduce the waste of unused spots. +#ifndef MICROPY_QSTR_POOL_MAX_ENTRIES +#define MICROPY_QSTR_POOL_MAX_ENTRIES (64) +#endif + // Initial amount for lexer indentation level #ifndef MICROPY_ALLOC_LEXER_INDENT_INIT #define MICROPY_ALLOC_LEXER_INDENT_INIT (10) diff --git a/py/qstr.c b/py/qstr.c index 49b2d9daa..de4dc6240 100644..100755 --- a/py/qstr.c +++ b/py/qstr.c @@ -144,14 +144,18 @@ STATIC qstr qstr_add(const byte *q_ptr) { // make sure we have room in the pool for a new qstr if (MP_STATE_VM(last_pool)->len >= MP_STATE_VM(last_pool)->alloc) { - qstr_pool_t *pool = m_new_ll_obj_var_maybe(qstr_pool_t, const char*, MP_STATE_VM(last_pool)->alloc * 2); + uint32_t new_pool_length = MP_STATE_VM(last_pool)->alloc * 2; + if (new_pool_length > MICROPY_QSTR_POOL_MAX_ENTRIES) { + new_pool_length = MICROPY_QSTR_POOL_MAX_ENTRIES; + } + qstr_pool_t *pool = m_new_ll_obj_var_maybe(qstr_pool_t, const char*, new_pool_length); if (pool == NULL) { QSTR_EXIT(); - m_malloc_fail(MP_STATE_VM(last_pool)->alloc * 2); + m_malloc_fail(new_pool_length); } pool->prev = MP_STATE_VM(last_pool); pool->total_prev_len = MP_STATE_VM(last_pool)->total_prev_len + MP_STATE_VM(last_pool)->len; - pool->alloc = MP_STATE_VM(last_pool)->alloc * 2; + pool->alloc = new_pool_length; pool->len = 0; MP_STATE_VM(last_pool) = pool; DEBUG_printf("QSTR: allocate new pool of size %d\n", MP_STATE_VM(last_pool)->alloc); |
