[generator.c] Mark ensure_valid_encoding as ALWAYS_INLINE.#975
[generator.c] Mark ensure_valid_encoding as ALWAYS_INLINE.#975byroot merged 1 commit intoruby:masterfrom
ensure_valid_encoding as ALWAYS_INLINE.#975Conversation
|
Could we achieve the same with force-inline instead? |
Admittedly I didn't try that, I was trying to be surgical. However... good question, so I tried it now. Looks like the answer is "yes". I'm not sure if this is random variation in benchmarks or if that's actually even better... I'll take it either way. I'll push that update in a second... Edit: Done. |
8839958 to
73320d6
Compare
valid_json_string_p conditional into json_object_i.ensure_valid_encoding as ALWAYS_INLINE.
Right. I was on my phone, so I didn't look at We can probably assume that we almost never receive invalid encoding, so we definitely want to inline the check, but the rest of the function probably shouldn't. The reason I suggested I'll force-push your PR to do that. |
And move the encoding convertion logic in another function with NOINLINE. The overwelming majority of strings are correctly encoded, so we want to inline the very cheap check, however we don't want to inline the much larger piece of code required to re-encode the string. Co-Authored-By: Jean Boussier <jean.boussier@gmail.com>
73320d6 to
2562c06
Compare
|
Updated. Let me know what you think. |
|
That change looks good, thank you! I confirmed that |
This PR forces
ensure_valid_encodingto be inlined.Saving the functional call overhead seems to provide a decent speedup in some of the realworld benchmarks.
Benchmarks
Benchmarks run on an M1 Macbook Air.
Compiled with: