Help optimize painfully slow Rust code ported from Java.
Good afternoon to all.
I currently having trouble with a port of a api I have written from Java.
I'm using Rocket to create the restful api, and Serde_json for json creation.
And all works well, except one of the crucial parts of the application is really slow compared to the Java version.
Basically I receive a HashMap of Strings from a function, and it is supposed to break up any entries that contain a '.' char in then into JSON Objects, as can be seen in this example.
To process a 25k map, the Java code takes about 500ms, and the Rust one takes about 8 to 10 seconds.
The reference Java Code looks like this. And my ported code looks like this.
Has anyone got any idea as to why it would be so slow?
Appreciate the help in advance.
Edit: the merge_json_value is my own implementation, so it could potentially be the slowdown also.
Edit2: I'm compiling the app in release mode, yes.
Edit3: Okay, just did some reading about less secure HashMaps. It indeed may help the performance.
But the thing is, I have another function which doesn't need to extract nested objects, and just converts a HashMap<String, String> to a serde_json::value::Value. That function outperforms the Java code by a lot. It is only this one which suffers from poor performance.
Edit4: Just to be sure, I tested the app with rustc-hash's FxHashMap. Unfortunately it didn't improve at all.