-
Notifications
You must be signed in to change notification settings - Fork 677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New External Magic String API to save heap memory #136
New External Magic String API to save heap memory #136
Conversation
*/ | ||
static uint32_t ecma_magic_string_ex_count = 0; | ||
static ecma_length_t* ecma_magic_string_ex_lengths = NULL; | ||
static jerry_get_magic_string_t ecma_magic_string_ex_handler = NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seanshpark, could we implement the external magic strings with registration of a constant structures array, using a structure like the following?
typedef struct
{
const jerry_char_t* value_p;
jerry_api_length_t length;
} jerry_ext_magic_string_t;
This way, we can improve performance by removing call to an external handler while getting value of an external magic string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with an jerry_ext_magic_string_t array I think ecma_magic_string_ex_handler is not needed any more. it can be accessed something like
ecma_magic_string_ex_table[id].value_p;
@seanshpark, do I understand correctly that the external magic strings mechanism is supposed to be used for registration of externally defined identifiers like |
@ruben-ayrapetyan , yes, you are right. reason is to save heap for byte codes. |
@seanshpark, thank you for explanation. That's great! |
@ruben-ayrapetyan , as memory consumption point of view, this implementation requires NUM_OF_STRINGS * sizeof(ecma_length_t = uint16_t) bytes for ecma_magic_string_ex_lengths array. when changed to structure it needs additional NUM_OF_STRINGS * sizeof(const jerry_char_t*) and as usually structure is aligned in 4 bytes, it'll be 4 times the size. for example, if there is about 256 items, it'll need 512 bytes to store lengths, and for structure 2048 (= 256 * (4+4)) bytes. when measure with last week iotjs JS script it saved about 1.8K for about 180 string items in total.(measured peak with mem-stats on) |
@ruben-ayrapetyan , updated PR so that string array is used without the handler but not by structure you mentioned. |
@seanshpark, I agree with you, that alignment of structure increases memory consumption and, so, using structure for defining external strings seems not to be the right way. Could you, please, change the Maybe, the lengths' array could be defined at compile-time similar to strings' array definition using In the case, we could make the strings' and lengths' arrays constant, would remove filling of externally defined array inside of engine, and, maybe, would remove runtime lengths' calculation. |
@ruben-ayrapetyan , thank you, PR is updated with your new idea. now no heap is used (I think). great. maybe we can change existing magic string like this one. |
* Initialize data for external string helpers | ||
*/ | ||
void | ||
ecma_strings_ex_init (const ecma_char_ptr_t* ex_str_items, uint32_t count, const ecma_length_t* ex_str_lengths) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you, please, add comments to the arguments?
/**< character arrays, representing
* external magic strings' contents */
/**< number of the strings */
/**< lengths of the strings */
Done as @ruben-ayrapetyan' comment. |
#if CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_ASCII | ||
typedef uint8_t jerry_api_char_t; | ||
#elif CONFIG_ECMA_CHAR_ENCODING == CONFIG_ECMA_CHAR_UTF16 | ||
typedef uint16_t jerry_api_char_t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, change the definitions using uint8_t and uint16_t with single definition using ecma_char_t.
@seanshpark, thank you for updating the changes. Could you please, reorder commits in the pull request, to fix build problem? After fixing build and API type definitions, the changes would look good for me. |
As for me, all tree commits should go with separate pull requests. @seanshpark after passing the review, please, apply these commits to master separately. |
cannot apply. compile error. ecma_globals.h is not included and I'm not sure it can be.
@egavrin , |
@seanshpark, thank you for update. Changes look good to me. Sorry for incorrect comment about type definitions. |
Great patch! |
JerryScript-DCO-1.0-Signed-off-by: SaeHie Park [email protected]
JerryScript-DCO-1.0-Signed-off-by: SaeHie Park [email protected]
* dump string literals with test_api to see jerry_register_external_magic_strings is working ok JerryScript-DCO-1.0-Signed-off-by: SaeHie Park [email protected]
Related issue: #109
JerryScript-DCO-1.0-Signed-off-by: SaeHie Park [email protected]