New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variant memory pools #61315
Variant memory pools #61315
Conversation
e3f06ec
to
930228a
Compare
@Calinou Would you be able to run quick benchmarks on this to see if it makes a significant change? |
PR Meeting:
Update: |
930228a
to
11a5f4d
Compare
7a312bb
to
ab8c72b
Compare
I'll try to do that this week. |
I ran a benchmark comparing this PR to the commit on SCons flags: Opening and quitting project managerBenchmark #1: bin/godot.linuxbsd.opt.tools.64 --quit
Time (mean ± σ): 2.518 s ± 0.049 s [User: 1.282 s, System: 0.192 s]
Range (min … max): 2.451 s … 2.571 s 10 runs
Benchmark #2: bin/godot.linuxbsd.opt.tools.64.variant_bucket_pools --quit
Time (mean ± σ): 2.500 s ± 0.055 s [User: 1.282 s, System: 0.193 s]
Range (min … max): 2.435 s … 2.584 s 10 runs
Summary
'bin/godot.linuxbsd.opt.tools.64.variant_bucket_pools --quit' ran
1.01 ± 0.03 times faster than 'bin/godot.linuxbsd.opt.tools.64 --quit' Opening and quitting editorBenchmark #1: bin/godot.linuxbsd.opt.tools.64 /tmp/4/project.godot --quit
Time (mean ± σ): 4.224 s ± 0.444 s [User: 2.990 s, System: 0.312 s]
Range (min … max): 3.616 s … 4.625 s 10 runs
Benchmark #2: bin/godot.linuxbsd.opt.tools.64.variant_bucket_pools /tmp/4/project.godot --quit
Time (mean ± σ): 4.246 s ± 0.433 s [User: 2.982 s, System: 0.321 s]
Range (min … max): 3.623 s … 4.633 s 10 runs
Summary
'bin/godot.linuxbsd.opt.tools.64 /tmp/4/project.godot --quit' ran
1.01 ± 0.15 times faster than 'bin/godot.linuxbsd.opt.tools.64.variant_bucket_pools /tmp/4/project.godot --quit' |
Yes I'll try and rebase this and also run some benchmarks. Expected it should be pretty similar for a lot of cases, as malloc (on desktop linux at least) is pretty good in the general case. At the least, pooling should not be slower than malloc, provided the implementation is sound, and your tests confirm this. To quote from wikipedia on benefits:
For myself the main attraction is the O(1) constant time operation, and the lack of fragmentation, housekeeping data and padding. Essentially you can really hammer a memory pool in recursive functions etc and not expect any glitches, whereas the same is not guaranteed with malloc. Also although I'm leading with this on 4.x, I'm hoping to do the same on 3.x, where the fragmentation can lead to problems particularly on 32 bit OS : e.g. #61835 Juan has also pointed out that using |
ab8c72b
to
f76c6e2
Compare
Memory pools via PagedAllocator for Transform2D, Transform3D, Basis and AABB.
f76c6e2
to
b221eab
Compare
Quick really naive benchmark from c++ suggests this PR is a little faster taking 3/4 of the time of old version:
Test B is actually just to save me compiling everything twice, as the old Variant news and deletes an AABB each time, so it is pretty much doing the same thing (maybe a little less in fact that the actual old Variant). Test C is just a confirmation repeat of A, to check for things like hot cache effects etc. So for my system (Linux Mint) the PagedAllocator appears to be > about 4/3 faster than malloc in this situation of hammering the allocator. I'm assuming @Calinou 's test before was just timing the startup, in which case it is unlikely to make a lot of difference. I'm also assuming the optimizer isn't doing something to throw off the timings, which is always a possibility with these things (the print statements are to prevent optimizing out). But as I say the primary reason (in my mind) is for the O(1) constant time allocation / deallocation, any increase in speed is a nice bonus. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Also approved by @reduz in PR meeting.
Thanks! |
Memory pools via PagedAllocator for Transform2D, Transform3D, Basis and AABB.
Simplified version of #58942 in response to PR meeting feedback, using a couple of bucket sizes - one for
Transform2D
andAABB
(6 reals), and one forBasis
andTransform3D
(12 reals).Notes
PagedAllocator
error messages during the fork indetect_prime()
, otherwise we would get false error messages. See Use memory pools for Variant extended types #58633 for more details._err_print_error
change is to allow at least basic printing of errors outside the lifetime of OS (for instance if OS is destroyed before PagedAllocator pools). Order of construction / destruction requires some care with pools such as these as other modules depend on them being present during startup and shutdown.