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

limit the scope of variables / functions #1

Open
ITotalJustice opened this issue Aug 18, 2022 · 2 comments
Open

limit the scope of variables / functions #1

ITotalJustice opened this issue Aug 18, 2022 · 2 comments

Comments

@ITotalJustice
Copy link

hi! i noticed in a few places in your code, your functions and variables are not made static, so the scope is extern.
this does have an effect of the codegen and subsequently binary size and performance.

examples are all of the cpu instructions and all global variables.

here's an example of what i mean https://godbolt.org/z/bvPYdooYv

@ITotalJustice
Copy link
Author

i was wrong in that example i sent, i thought it was odd that the codegen was different for arrays. because the variable was static and never written to, the compiler almost entirely optimised out the array access in array_read2. here is a fixed version https://godbolt.org/z/EnYzYja7a

i still feel its worth limiting the scope for global variables. especially functions :)

@Hydr8gon
Copy link
Owner

Good point. I always forget to do that, heh.

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

No branches or pull requests

2 participants