Skip to content
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

Introduce a block pool for performance? #98

Open
homonoidian opened this issue May 7, 2023 · 2 comments
Open

Introduce a block pool for performance? #98

homonoidian opened this issue May 7, 2023 · 2 comments
Assignees
Labels
optimization Improvements to the speed

Comments

@homonoidian
Copy link
Collaborator

Disposed blocks can be released to the ObjectPool or a variation thereof, at Block.new we can try looking at free blocks and using ones if possible (by initializeing over them), orelse doing a Block.allocate and storing the result in the pool.

This of course requires at least refcounting. As a matter of trade-off we can perhaps use a very simple refcounting approach (the one that breaks at cyclic references etc.). This shouldn't be too hard, just a few is_a?s in Block#add and others, increments/decrements in Block#parent= and others. After all, we're backed by Crystal's GC anyway, ± few blocks shouldn't be a problem.

This whole thing may not be worth it though; I have no idea. This depends on how many throwaway blocks are there in core/tests/Novika apps, and this I don't know. I guess there is only one way to find out!

@homonoidian homonoidian added the optimization Improvements to the speed label May 7, 2023
@homonoidian homonoidian self-assigned this May 7, 2023
@homonoidian
Copy link
Collaborator Author

Although probably this will require a mark&sweep (ish) stage, although rare (like 10s or 100s of thousands of ticks rare), to clear used but unreachable blocks — Crystal's GC won't be able to do that because there's one reference, the one in the "used" list, and so they will never get collected unless we do it ourselves.

@homonoidian
Copy link
Collaborator Author

(and the word "clear" above should mean move to the free list, I guess)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
optimization Improvements to the speed
Projects
None yet
Development

No branches or pull requests

1 participant