Skip to content

Commit b78ce28

Browse files
committed
[perf] fix some minor bugs in json-lines processing
1 parent f303347 commit b78ce28

5 files changed

Lines changed: 21 additions & 16 deletions

File tree

src/log_format.cc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,11 +1138,12 @@ struct json_log_userdata {
11381138
== field_frag)
11391139
{
11401140
auto retval
1141-
= format->elf_value_def_read_order[this->jlu_read_order_index++]
1141+
= format->elf_value_def_read_order[this->jlu_read_order_index]
11421142
.second;
11431143
if (retval != nullptr) {
11441144
this->jlu_precision += 1;
11451145
}
1146+
this->jlu_read_order_index += 1;
11461147
return retval;
11471148
}
11481149

@@ -1407,7 +1408,9 @@ json_array_end(void* ctx)
14071408
{
14081409
auto* ypc = (yajlpp_parse_context*) ctx;
14091410
auto* jlu = (json_log_userdata*) ypc->ypc_userdata;
1410-
const auto* vd = jlu->get_field_def(ypc);
1411+
const auto* vd = ypc->ypc_path_index_stack.size() > 1
1412+
? jlu->get_field_def(ypc)
1413+
: nullptr;
14111414

14121415
if (ypc->ypc_path_index_stack.size() == 1 || vd != nullptr) {
14131416
intern_string_t field_name;
@@ -1438,7 +1441,9 @@ read_array_end(void* ctx)
14381441
{
14391442
auto* ypc = (yajlpp_parse_context*) ctx;
14401443
auto* jlu = (json_log_userdata*) ypc->ypc_userdata;
1441-
const auto* vd = jlu->get_field_def(ypc);
1444+
const auto* vd = ypc->ypc_path_index_stack.size() > 1
1445+
? jlu->get_field_def(ypc)
1446+
: nullptr;
14421447

14431448
if (ypc->ypc_path_index_stack.size() == 1 || vd != nullptr) {
14441449
const intern_string_t field_name = ypc->get_path_fragment_i(0);

src/log_format_ext.hh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,11 @@ public:
343343
value_defs_state elf_specialized_value_defs_state;
344344

345345
std::vector<std::shared_ptr<value_def>> elf_value_def_order;
346-
robin_hood::unordered_map<string_fragment, value_def*, frag_hasher>
346+
robin_hood::unordered_map<string_fragment,
347+
value_def*,
348+
frag_hasher,
349+
std::equal_to<string_fragment>,
350+
50>
347351
elf_value_def_frag_map;
348352
std::vector<std::pair<string_fragment, value_def*>>
349353
elf_value_def_read_order;

src/log_vtab_impl.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,11 +2529,6 @@ vt_update(sqlite3_vtab* tab,
25292529
argc, argv, 2 + vt->footer_index(log_footer_columns::annotations));
25302530
auto log_opid = from_sqlite<std::optional<string_fragment>>()(
25312531
argc, argv, 2 + vt->footer_index(log_footer_columns::opid));
2532-
const auto log_user_opid
2533-
= from_sqlite<std::optional<string_fragment>>()(
2534-
argc,
2535-
argv,
2536-
2 + vt->footer_index(log_footer_columns::user_opid));
25372532
bookmark_metadata tmp_bm;
25382533
parsed_tags tmp_tags;
25392534

src/yajl/yajl_encode.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,13 @@ void yajl_string_decode(yajl_buf buf, const unsigned char * str,
122122
props->has_ansi = 0;
123123
props->line_feeds = 0;
124124
while (end < len) {
125-
if (str[end] == '\x1b') {
126-
props->has_ansi = 1;
127-
end++;
128-
} else if (str[end] == '/' || str[end] == '#' || str[end] == '~') {
125+
if (str[end] == '/' || str[end] == '#' || str[end] == '~') {
129126
props->ptr_escapes += 1;
130127
end++;
131128
} else if (str[end] == '\\') {
132129
char utf8Buf[5];
133130
const char * unescaped = "?";
131+
unsigned int unescapedLen = 1;
134132
yajl_buf_append(buf, str + beg, end - beg);
135133
switch (str[++end]) {
136134
case 'r': unescaped = "\r"; break;
@@ -157,7 +155,6 @@ void yajl_string_decode(yajl_buf buf, const unsigned char * str,
157155
| (surrogate & 0x3FF));
158156
end += 5;
159157
} else {
160-
unescaped = "?";
161158
break;
162159
}
163160
} else if (codepoint == 0x1b) {
@@ -168,6 +165,10 @@ void yajl_string_decode(yajl_buf buf, const unsigned char * str,
168165

169166
Utf32toUtf8(codepoint, utf8Buf);
170167
unescaped = utf8Buf;
168+
if (codepoint < 0x80) unescapedLen = 1;
169+
else if (codepoint < 0x800) unescapedLen = 2;
170+
else if (codepoint < 0x10000) unescapedLen = 3;
171+
else unescapedLen = 4;
171172

172173
if (codepoint == 0) {
173174
yajl_buf_append(buf, unescaped, 1);
@@ -180,7 +181,7 @@ void yajl_string_decode(yajl_buf buf, const unsigned char * str,
180181
default:
181182
assert("this should never happen" == NULL);
182183
}
183-
yajl_buf_append(buf, unescaped, (unsigned int)strlen(unescaped));
184+
yajl_buf_append(buf, unescaped, unescapedLen);
184185
beg = ++end;
185186
} else {
186187
end++;

src/yajl/yajl_parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ yajl_do_parse(yajl_handle hand, const unsigned char * jsonText,
384384
yajl_need_key(hand->lexer, 1);
385385
tok = yajl_lex_lex(hand->lexer, jsonText, jsonTextLen,
386386
offset, &buf, &bufLen, &str_props);
387-
yajl_need_key(hand->lexer, 1);
387+
yajl_need_key(hand->lexer, 0);
388388
switch (tok) {
389389
case yajl_tok_eof:
390390
return yajl_status_ok;

0 commit comments

Comments
 (0)