-
Notifications
You must be signed in to change notification settings - Fork 688
Use binary search for keyword checking #2584
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
Use binary search for keyword checking #2584
Conversation
|
Performance results:
|
|
This PR has some overlapping with #2574 |
2406026 to
5d06d39
Compare
jerry-core/parser/js/js-lexer.c
Outdated
| { | ||
| const keyword_string_t *keyword_p; /**< keyword string list */ | ||
| const uint8_t length; /**< keyword list length */ | ||
| } keyword_string_list_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.
It is true, that 8 bit length is more than enough, but the first member is a pointer, so the whole structure will be pointer aligned (so we waste 3 byte with 32 bit pointers). What about creating two arrays:
static const keyword_string_t * const keyword_strings_list[]
static const uint8_t keyword_lengths_list[]
(Note: an s added after 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.
It seems reasonable. Good idea!
jerry-core/parser/js/js-lexer.c
Outdated
| * Keywords with 3 characters. | ||
| */ | ||
| static const keyword_string_t keyword_length_3[6] = | ||
| static const keyword_string_t keyword_length_3[] = |
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.
This is just an idea, but what about renaming these to keywords_with_length_3 or keywords_of_length_3, I don't know which one is correct. Since we touch this code anyway. Or keyword_group_with_length_3. I am open to other suggestions.
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.
+1 for keywords_with_length_3.
5d06d39 to
ccf32f5
Compare
jerry-core/parser/js/js-lexer.c
Outdated
| #define LEXER_KEYWORD(name, type) { (const uint8_t *) (name), (type) } | ||
| #define LEXER_KEYWORD_END() { (const uint8_t *) NULL, LEXER_EOS } | ||
| #define LEXER_KEYWORD_LIST_LENGTH(name) (const uint8_t) (sizeof ((name)) / sizeof ((name)[0])) | ||
| #define LEXER_KEYWORD_END() |
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.
The LEXER_KEYWORD_END() is still needed?
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.
Good catch! It's a leftover code.
ccf32f5 to
8a07389
Compare
|
@zherczeg @robertsipka The patch is updated according to your suggestions, also rebased to the latest master. |
zherczeg
left a comment
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.
Good patch, nearly done.
jerry-core/parser/js/js-lexer.c
Outdated
| if (relation == 0) | ||
| { | ||
| if (keyword_p->type >= LEXER_FIRST_FUTURE_STRICT_RESERVED_WORD) | ||
| relation = memcmp (ident_start_p, keyword_p->keyword_p, length); |
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.
I would cal this compare_result
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.
True, sounds better.
This patch improves keyword searching during identifier parsing. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
8a07389 to
41bcb42
Compare
|
Nice patch, LGTM. |
zherczeg
left a comment
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.
LGTM
This patch improves keyword searching during identifier parsing.
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu