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

fn *intra_pred_dsp_init*: Cleanup and make safe #584

Merged
merged 4 commits into from
Dec 6, 2023

Conversation

kkysen
Copy link
Collaborator

@kkysen kkysen commented Nov 21, 2023

No description provided.

@kkysen kkysen requested a review from randomPoison November 21, 2023 23:11
@thedataking
Copy link
Collaborator

thedataking commented Nov 22, 2023

I think it would be wise to delete all uses of bd_fn and similar macros. It optimizes for code compactness instead of readability which I think is the wrong tradeoff. We can simply have:

dsp_init_fn(...)

match bitdepth {
    8 => { init all the 8bpc stuff here }
    16 => { init all the 16bpc stuff here }
} 

This of course makes the code twice as long but more than twice as readable. I don't have to read the bd_fn macro figure out what is going on, I can just see what function is being called directly and I can click on the function name in my IDE to go to the callee. Constructing the function name in a macro is just not worth the mental overhead and hassle IMO.

@kkysen
Copy link
Collaborator Author

kkysen commented Nov 22, 2023

I think it would be wise to delete all uses of bd_fn and similar macros. It optimizes for code compactness instead of readability which I think is the wrong tradeoff. We can simply have:

dsp_init_fn(...)

match bitdepth {
    8 => { init all the 8bpc stuff here }
    16 => { init all the 16bpc stuff here }
} 

This of course makes the code twice as long but more than twice as readable. I don't have to read the bd_fn macro figure out what is going on, I can just see what function is being called directly and I can click on the function name in my IDE to go to the callee. Constructing the function name in a macro is just not worth the mental overhead and hassle IMO.

I respectfully disagree, and I feel like we've (including @randomPoison) discussed it before. The bd_fn! way is significantly more readable to me, and C is using a similar macro here, too. If they're all fully expanded, you're never going to notice if one of them is subtly different, but you would if you couldn't use bd_fn! and the difference is glaringly obvious. Hence why I feel it's more readable. It's a consistent, single pattern used throughout the codebase. It's hiding the redundant information that obscures the important information, making it much more readable. And our main focus is safety, performance, and making things safe as fast as possible, not focusing on readability and ergonomics yet. Porting it to use bd_fn! has been much faster for me with much fewer subtle bugs, which I made accidentally more often when I expanded the macro on my initial attempt before adding bd_fn!.

@thedataking
Copy link
Collaborator

thedataking commented Nov 25, 2023

we've (including @randomPoison) discussed it before

Yes, we struck a reasonable compromise in PR #322 .

Since then, it seems bd_fn and wrap_fn_ptr got added so now the reader has more to parse through to figure out what is happening.

We should not spend our time compactifying the code by wrapping macros in other macros. Readers that aren't you are not going to find it as readable as you do; I'm among them. That said, I acknowledge your point that the C code uses macros here. I'll let @randomPoison decide what is the best way forward.

@kkysen kkysen force-pushed the kkysen/struct-Rav1dIntraPredDSPContext-defaults branch from 662f110 to 1d210ad Compare November 27, 2023 06:27
@kkysen kkysen force-pushed the kkysen/cleanup-fns-intra_pred_dsp_init branch 2 times, most recently from 4a60b90 to eccc29a Compare November 29, 2023 07:18
@kkysen kkysen force-pushed the kkysen/struct-Rav1dIntraPredDSPContext-defaults branch 2 times, most recently from ca53d47 to f2c5e8f Compare November 29, 2023 07:41
@kkysen kkysen force-pushed the kkysen/cleanup-fns-intra_pred_dsp_init branch from eccc29a to 86d472d Compare November 29, 2023 07:44
@kkysen kkysen force-pushed the kkysen/struct-Rav1dIntraPredDSPContext-defaults branch from f2c5e8f to 7d0c2ce Compare November 30, 2023 07:05
@kkysen kkysen force-pushed the kkysen/cleanup-fns-intra_pred_dsp_init branch from 86d472d to 91c1922 Compare November 30, 2023 07:05
@rinon
Copy link
Collaborator

rinon commented Dec 2, 2023

We've discussed the macros and function pointer wrapping. While there may have been other ways to do this with less complexity or effort, I think that what we have now is usable (now that it's documented) and I don't think we should spend any more time here in either refining or removing the current implementation.

This PR LGTM, the discussion here is not actually relevant for this PR itself, more of a meta-discussion. I would suggest we merge this and the previous changes and move on with what we have here.

@kkysen kkysen force-pushed the kkysen/struct-Rav1dIntraPredDSPContext-defaults branch from 7d0c2ce to 4609590 Compare December 2, 2023 05:04
@kkysen kkysen force-pushed the kkysen/cleanup-fns-intra_pred_dsp_init branch from 91c1922 to dab1eef Compare December 2, 2023 05:04
Base automatically changed from kkysen/struct-Rav1dIntraPredDSPContext-defaults to main December 6, 2023 04:46
@kkysen kkysen merged commit a62375e into main Dec 6, 2023
18 checks passed
@kkysen kkysen deleted the kkysen/cleanup-fns-intra_pred_dsp_init branch December 6, 2023 04:46
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

Successfully merging this pull request may close these issues.

3 participants