Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Nice performance boost for handling boolean values #36

Closed
wants to merge 2 commits into from

Conversation

mre
Copy link
Owner

@mre mre commented Jul 19, 2018

We can serialize to bool directly without using extract.
This gives us a nice performance boost as can be seen in the new plots.
The same trick can probably be applied elsewhere.
Good places to look for such improvements are the remaining extract calls and the macro handling for casts.

src/lib.rs Outdated
} else if let Ok(key) = key.str() {
let key = key.to_string().map_err(debug_py_err)?;
map.serialize_key(&key)?;
match key {
Cow::Borrowed("true") => map.serialize_key(&true)?,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this branch is needed -- a boolean key true and a string key "true" serialize exactly the same in JSON.

Copy link
Owner Author

@mre mre Jul 19, 2018

Choose a reason for hiding this comment

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

Just to be clear, you mean we could get rid of the match for Cow::Borrowed("true") and Cow::Borrowed("false") and simply always use the _ case?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Seems to work in the unit tests at least. 😅 Let me push that change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes.

@dtolnay
Copy link
Contributor

dtolnay commented Jul 19, 2018

Which of the graphs are you looking at? To me it looks like the 100 dicts array was substantially faster before (left) than after (right).

selection_003

@mre
Copy link
Owner Author

mre commented Jul 19, 2018

Oh. You're right. 😞 Maybe it was just wishful thinking on my side.
I could swear that I saw different values before, though...
Anyway, my reasoning was that extract is a rather expensive call, which might not be true. No idea where the performance degradation comes from in this case. Any guess?

@dtolnay
Copy link
Contributor

dtolnay commented Jul 19, 2018

I don't think we will be able to make reasonable progress on performance just by trying code changes. I would recommend getting a reliable perf set up so that we have a clear picture of where the time is going.

@mre
Copy link
Owner Author

mre commented Jul 19, 2018

Duly noted. I'm on a Mac and it feels like the Linux support is better when it comes to profiling Rust code. There are still options of course like @carols10cents' write-up here or this experimental profiler for mac.
Nevertheless, a hosted solution that triggers on every PR would be better, but I don't know of any such service.

@mre mre closed this Jul 19, 2018
@mre
Copy link
Owner Author

mre commented Jul 19, 2018

Closing this PR as it was misguided. Sorry for that.
Still open to perf setup suggestions, though. 😜

@mre mre mentioned this pull request Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants