-
Notifications
You must be signed in to change notification settings - Fork 119
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
Implementing pool allocator #678
Comments
Pools make me nervous. There is a long history of people trying to improve on malloc, only to have things blow up (ie. got slower, leak memory, be buggy). There are several memory-pool malloc-replacement/add-on libraries out there, they might be worth playing with. But you can try this, I guess -- just be careful with limiting complexity... |
My implementation is not too different than this. |
Yeah, OK, that seems both harmless and likely to improve performance. |
I finished the memory pool implementation and got these speedups:
The only place I used it in the dictionary read handling is to allocate the connector descriptor elements (condesc_t). I guess that using it for allocation Dict_node may improve read performance. There are more places in which it can be used, e.g. building disjunct, postprocessing, linkage extracting. In exprune.c I have left the specially tailored memory pool I recently introduced because it performs somewhat better than my general purpose implementation and has a small enough code. In Memory pools have a drawback that element memory overflow cannot be found with ASAN, and they need a special valgrind support incorporated into them in order that valgrind will be able to make memory checks on them (and I didn't implement that). To solve this drawback, I also wrote a "fake memory pool" support, that just uses "malloc()" for each element, and it is used if the library is compiled with If these savings seem fine for introducing such an infrastructure, I will polish it some more and send a PR. |
Sure. The above-mentioned design seemed reasonable, and the speedups are worthwhile. |
In #673 I implemented a pool allocator in the exprune code.
The idea was to malloc big chunks of memory and then sub-allocate each element from these chunks.
This prevents absolutely most of the overhead of malloc/free. It also allows zeroing (if needed) of the whole pool at once instead of each element separately. This particular pool is reused in each pruning round, but this is not needed for a general use.
The disjunct/connector packing also use a kind of pool allocator.
My proposal is to implement this idea in a general way, by a simple pool allocator.
(The pools are to be freed after handling each sentence, at least for now - this can be changed if desired.)
Proposed API (pool_alloc.c, pool_alloc.h):
My current implementation about is 30 lines of code, but I guess some more will added.
Using such pools makes it more tricky to free all sentence memory in case memory is exhausted (a planned work), but it is "easily" possible too.
The text was updated successfully, but these errors were encountered: