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

Smaller HPyContext to prepare it for stack-allocation. #330

Open
fangerer opened this issue Jun 10, 2022 · 5 comments
Open

Smaller HPyContext to prepare it for stack-allocation. #330

fangerer opened this issue Jun 10, 2022 · 5 comments
Assignees

Comments

@fangerer
Copy link
Contributor

We discussed having a stack-allocated context some time ago but never really made a decision nor summarized everything.
I wrote a document about that. Since that seemed to be a too long for an issue description, the document can be found in the Wiki:
https://github.com/hpyproject/hpy/wiki/Stack-allocated-HPyContext

@fangerer fangerer self-assigned this Jun 10, 2022
@antocuni
Copy link
Collaborator

I read the wiki but I'm a bit confused about the terminology. If I understand it correctly, we are talking about two different things:

  1. the layout of HPyContext: here the question is basically whether we want a single or double indirection is this correct?
  2. how to allocate HPyContext: this is the stack vs heap allocation discussion, but again if I understand correctly it's a graalpython specific discussion, isn't it? E.g., for CPython and PyPy the HPyContext will likely continue to be a singleton.

And the link between (1) and (2) is that stack allocation is possible only if sizeof(HPyContext) is small, i.e. only if we use double indirection.

Is my summary correct, or I am missing anything?

@fangerer
Copy link
Contributor Author

Concerning the link: yes.

You are right. If we change the context layout to what I've suggested, then other runtimes are still free to allocate the context on the heap. I'll try to make that clear in the document ASAP.

@antocuni
Copy link
Collaborator

I am not opposed to change the layout of HPyContext, but the first thing to do is to measure the performance penalty and then decide based on that (especially on CPython)

@fangerer
Copy link
Contributor Author

I absolutely agree. I will design various benchmarks.

@hodgestar
Copy link
Contributor

One way to make the context slightly smaller would be to replace the ctx->h_None and similar handles with a fixed list of constant handles. This would be most awkward on CPython where the handles currently really are pointers.

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

No branches or pull requests

3 participants