Skip to content

Conversation

@cplaursen
Copy link
Contributor

Updated implementation to use map_unlikely, which is optimised for this sort of thing.

Signed-off-by: Christian Pardillo Laursen <christian.pardillolaursen@citrix.com>
Copy link
Contributor

@edwintorok edwintorok left a comment

Choose a reason for hiding this comment

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

Assuming that the map_unlikely function works correctly, this looks good.
If we want to be sure could add a quickcheck test with a copy of the old implementation and new implementations and have it try to find differences in behaviour.

There are examples of QCheck2 usage in XAPI already

@psafont
Copy link
Member

psafont commented Nov 25, 2025

Are there any mini benchmarks to see the improvement?

I have a wip branch with more cleanup around strings, especially consolidating escaping functions, which might be a worthwile thing to revise while you're on the area. Unfortunately I don't have much time to test the changes, which is why I haven't opened a PR.

master...psafont:xen-api:dev/pau/strings

The series removes map_unlikely, and changes escaped. That needs to be changed to work well with your change, of course

@cplaursen
Copy link
Contributor Author

I'm happy to produce some benchmarks with the tests. I'll also take a look at the branch you've linked, thank you, though I'll focus on getting this change through for now.

Signed-off-by: Christian Pardillo Laursen <christian.pardillolaursen@citrix.com>
@cplaursen
Copy link
Contributor Author

Benchmarking against a naive implementation gives:

String size 100:
  Optimized: 1789.445 μs
  Reference: 2478.163 μs
  Improvement: 27.8% faster

String size 500:
  Optimized: 8766.232 μs
  Reference: 12855.552 μs
  Improvement: 31.8% faster

String size 1000:
  Optimized: 17661.768 μs
  Reference: 26854.626 μs
  Improvement: 34.2% faster

@cplaursen
Copy link
Contributor Author

It would be good to have a unified benchmark markup library within xapi, rather than reproducing bechamel_simple_cli.ml whenever a benchmark is needed

@lindig
Copy link
Contributor

lindig commented Nov 25, 2025

I would expect an improvement that is not visible in the benchmark: this creates much less memory garbage and that improvement will not show up in the benchmark, I would assume.

@cplaursen cplaursen force-pushed the xstringext-perf branch 2 times, most recently from f639e06 to 4d57100 Compare November 25, 2025 16:27
Signed-off-by: Christian Pardillo Laursen <christian.pardillolaursen@citrix.com>
@cplaursen cplaursen added this pull request to the merge queue Nov 25, 2025
Merged via the queue into xapi-project:master with commit 8979e27 Nov 25, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants