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

Cleanup #826

Merged
merged 6 commits into from
Apr 15, 2022
Merged

Cleanup #826

merged 6 commits into from
Apr 15, 2022

Conversation

Jan200101
Copy link
Contributor

@Jan200101 Jan200101 commented Jan 30, 2022

Update meson.build

  • add logic to loop over more lua names (in the future more names might be discovered)
    • also fixes error where forcing fallback would compile lua dynamically
  • disable warnings and errors on dependencies

adding missing includes and checks, correct data types, pointer mess

  • various functions from string.h were used but never defined
  • logic was done across multiple different data types with different signedness, got all of them up to snuff
  • give 0 sized array size of 1 (array of size 0 is illegal, but rewriting the code is out of the scope of this commit)
  • add preprocessor that marks possibly unused argument as such (does not mean they will get optimized out or anything)
  • correctly initialize structs with all data needed
  • work around function pointers and data pointers being used like they are the same (thats illegal)

src/rencache.c Outdated Show resolved Hide resolved
src/rencache.c Outdated
@@ -159,7 +160,7 @@ void rencache_invalidate(void) {
}


void rencache_begin_frame(lua_State *L) {
void rencache_begin_frame(UNUSED lua_State *L) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing it moved the UNUSED from this to f_begin_frame

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't those lua_States be useful in case we add support for multiple windows?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure; but we can always add them back in when and if that happens. As it stands, if it's causing a warning, let's just nix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to keep so that the signature of all rencache functions stays similar.
We cannot remove lua_State from the f_{begin,end}_frame functions so it might be worth to keep this

src/rencache.c Outdated
@@ -200,7 +201,7 @@ static void push_rect(RenRect r, int *count) {
}


void rencache_end_frame(lua_State *L) {
void rencache_end_frame(UNUSED lua_State *L) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removing it moved the UNUSED from this to f_end_frame

src/rencache.c Outdated Show resolved Hide resolved
src/api/process.c Outdated Show resolved Hide resolved
Copy link
Contributor Author

@Jan200101 Jan200101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more stuff

This now compiles using zig cc

src/renderer.c Show resolved Hide resolved
src/renderer.c Show resolved Hide resolved
Copy link
Contributor Author

@Jan200101 Jan200101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this through CodeChecker and found some additional things

src/renderer.c Show resolved Hide resolved
src/api/process.c Outdated Show resolved Hide resolved
src/api/process.c Show resolved Hide resolved
if (new_fds[stream] > STDERR_FD || new_fds[stream] < REDIRECT_PARENT) {
for (size_t i = 0; i < env_len; ++i) {
free((char*)env_names[i]);
free((char*)env_values[i]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah; this is a good point; ideally though we'd probably have this as separate logic, rather than repeating it. Perhaps goto? That is the standard way of doing exception handling in C.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the problem right now is that the code is not designed around this but I can look into this

src/renderer.c Outdated
r = (color.r * src.r * color.a + dst.r * (65025 - src.r * color.a) + 32767) / 65025;
g = (color.g * src.g * color.a + dst.g * (65025 - src.g * color.a) + 32767) / 65025;
b = (color.b * src.b * color.a + dst.b * (65025 - src.b * color.a) + 32767) / 65025;
*destination_pixel++ = dst.a << surface->format->Ashift | r << surface->format->Rshift | g << surface->format->Gshift | b << surface->format->Bshift;
*destination_pixel++ = SDL_MapRGBA(surface->format, r, g, b, dst.a);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the proper way™ makes things a bit slower. On my system this change increases CPU usage by ~7%, both with and without LITE_USE_SDL_RENDERER.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function calls are more expensive than doing it directly, I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the overhead could come from having to dynamically resolve the symbol.

Another guess would be that the SDL_expand_byte lookup is more expensive than just doing naive bit shifts.

This might be worth investigating further to see where the difference comes from.

@adamharrison
Copy link
Member

So I'd like to merge this, but I'd like to not lose any performance on the tight loop. Can we just revert that bit, and leave a comment above it that it's out of standard, so that we don't lose the performance, but still keep an eye on it?

- add logic to loop over more lua names (in the future more names might be discovered)
- disable warnings and errors on dependencies
- various functions from string.h were used but never defined
- logic was done across multiple different data types with different signedness, got all of them up to snuff
- give 0 sized array size of 1 (array of size 0 is illegal, but rewriting the code is out of the scope of this commit)
- add preprocessor that marks possibly unused argument as such (does not mean they will get optimized out or anything)
- correctly initialize structs with all data needed

All these were found by generating the project using `meson -Dwarning_level=3 -Dwerror=true`
@Jan200101 Jan200101 requested a review from adamharrison April 5, 2022 08:39
@adamharrison
Copy link
Member

OK, I've tested this, and it looks good. Merging.

@adamharrison adamharrison merged commit fff10a2 into lite-xl:master Apr 15, 2022
@Jan200101 Jan200101 deleted the cleanup branch April 15, 2022 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants