(Option 2) Fixed O(N^2) performance when handling --bind flags #630
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #384. Same Pull Request as #629 (please read it). But I've been thinking about changes I have made and realized that maybe segment trees with lazy propagation is a little bit overengineering just to set flags. In this branch I've removed the whole segment tree data structure and replaced it with boolean arrays.
When segment tree uses lazy propagation to assign value on the interval and uses recursive algorithm to retrieve actual value on the index, current implementation just
memset()
the needed part of array to set flags and access needed flag by index. In all other respects, the algorithm remains unchanged.Technically here we revert back to O(N^2) complexity, but compiler optimizations and speed of
memset
performs also great on even big amounts of mount points. At the same time, if we run some more complex benchmarks, maybe with hundreds of thousands mount points, there's a great possibility that segment trees will perform better.At the same time, again, boolean array takes really much less memory than segment tree (4N) of integers. And it's a big advantage. Also, It's just more simple.
With this approach we can also try to inline all the check/set flags function. I've tried. Nothing changed. Maybe it became a little slower. Anyway, there's such possibility.
It's a way more simple to understand and debug
My benchmark with memset approach:
flatpak run com.microsoft.Edge
Without optimization => memset approach => segtree approach
A test where I pass bwrap 2000 "--bind" flags:
bwrap --dev-bind / / --bind /usr /tmp/1 --bind /usr /tmp/2 ... --bind /usr /tmp/2000 /bin/true