Skip to content

[API] Improve the performance of the external magic id search #1506

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

Merged
merged 1 commit into from
Jan 9, 2017

Conversation

bzsolt
Copy link
Member

@bzsolt bzsolt commented Dec 22, 2016

After this patch, we have to provide external strings ordered by size and lexicographically.
We can do this with jerry_parse_and_save_literals() (#1500).

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély [email protected]

@bzsolt bzsolt added api Related to the public API performance Affects performance labels Dec 22, 2016
@@ -157,6 +157,22 @@ lit_magic_strings_ex_set (const lit_utf8_byte_t **ex_str_items, /**< character a
lit_utf8_size_t string_size = lit_zt_utf8_string_size (lit_get_magic_string_ex_utf8 (id));
JERRY_ASSERT (JERRY_CONTEXT (lit_magic_string_ex_sizes)[id] == string_size);
JERRY_ASSERT (JERRY_CONTEXT (lit_magic_string_ex_sizes)[id] <= LIT_MAGIC_STRING_LENGTH_LIMIT);

/* Check the order of the strings */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add more description here. What is the right order? Maybe with a small example.

@bzsolt bzsolt force-pushed the search-ext-strings branch from abf81a7 to b4859e1 Compare January 3, 2017 12:57
const lit_utf8_byte_t *prev_ex_string_p = lit_get_magic_string_ex_utf8 (prev_id);
const lit_utf8_byte_t *curr_ex_string_p = lit_get_magic_string_ex_utf8 (id);
const int string_compare = memcmp (prev_ex_string_p, curr_ex_string_p, string_size);
JERRY_ASSERT (string_compare < 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JERRY_ASSERT (memcmp (prev_ex_string_p, curr_ex_string_p, string_size) < 0)

}
else if (found_size_range)
{
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is correct?

a
b
c
d
e
ff
gg

Search e.

First, you find d, and found_size_range is set to 1. Then you find ff, and the loop aborts. If I understand correctly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed it, thanks.

After this patch, we have to provide external strings ordered by size and lexicographically.
We can do this with jerry_parse_and_save_literals() (jerryscript-project#1500).

JerryScript-DCO-1.0-Signed-off-by: Zsolt Borbély [email protected]
@bzsolt bzsolt force-pushed the search-ext-strings branch from b4859e1 to f6c6937 Compare January 4, 2017 11:19
Copy link
Contributor

@LaszloLango LaszloLango left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -150,8 +150,8 @@ handler_construct (const jerry_value_t func_obj_val, /**< function object */
*/
#define JERRY_MAGIC_STRING_ITEMS \
JERRY_MAGIC_STRING_DEF (GLOBAL, global) \
Copy link
Contributor

@robertsipka robertsipka Jan 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The global is already in the list of ECMA magic strings, so it doesn't have to be an external magic string because the defined magic string id will be found at first. But I think it could be removed in a follow-up patch, otherwise LGTM (informally).

Copy link
Member

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@LaszloLango LaszloLango merged commit 1c38c12 into jerryscript-project:master Jan 9, 2017
@bzsolt bzsolt deleted the search-ext-strings branch January 9, 2017 09:32
janjongboom added a commit to janjongboom/jerryscript that referenced this pull request Jan 10, 2017
Magic strings are expected to be sorted by length, then alphabetically after jerryscript-project#1506 landed. This breaks the mbedos5 target against JerryScript master as it emits the pins in the order that it finds the pins. This patch sorts the pin names.

JerryScript-DCO-1.0-Signed-off-by: Jan Jongboom [email protected]
zherczeg pushed a commit that referenced this pull request Jan 11, 2017
Magic strings are expected to be sorted by length, then alphabetically after #1506 landed. This breaks the mbedos5 target against JerryScript master as it emits the pins in the order that it finds the pins. This patch sorts the pin names.

JerryScript-DCO-1.0-Signed-off-by: Jan Jongboom [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to the public API performance Affects performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants