-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Don't use memcmp() to compare TextAttributes, instead just reorder the data member comparisons #12866
Conversation
…ysical order for generated code quality improvement
…rminal into textattributeopequal
@check-spelling-bot ReportUnrecognized words, please review:
Previously acknowledged words that are now absentazurewebsites cxcy DCompile debolden deconstructed devicefamily GETKEYSTATE guardxfg LLVM LPCHARSETINFO MAPVIRTUALKEY MSDL ned NOWAIT pgorepro pgort PGU redistributable Timeline timelines unintense UWA UWAs VKKEYSCAN WResult xfgTo accept these unrecognized words as correct (and remove the previously acknowledged and now absent words), run the following commands... in a clone of the git@github.com:EmJayGee/terminal.git repository
✏️ Contributor please read thisBy default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.
If the listed items are:
See the 🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉 🗜️ If you see a bunch of garbageIf it relates to a ... well-formed patternSee if there's a pattern that would match it. If not, try writing one and adding it to a Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines. Note that patterns can't match multiline strings. binary-ish stringPlease add a file path to the File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
|
OK I have no idea how to fix this. I have made the spelling error fixes in my branch in my fork, but I don't know where to go from here. I will see if I can keep moving ahead. |
aha all I had to do is check in to the branch and push to the fork. I guess that's part of why I couldn't delete the branch in the last issue. |
I looked at the generated code again and it's not as good as I thought. I will take another crack at it. I'm surprised at how poor it is. I'd ask the compiler team if it were prohibited from writing the optimizations I would expect here if I was still there but I'm not so. instead I'm led to try writing something that violates the "const refs can actually be passed by value" detente but if a 14 byte struct is ever actually passed by value, I'll find a hat and eat it. I guess when we have 128 bit processors. |
Amen. Thanks for looking into this as much as you have been! 😄 |
OK so this code generates pretty much what is desirable. If this is a really hot path, it's possible that a branchless solution would be faster if this is as hot as the other PR author suggested but I think we might be hitting diminishing returns for esoterica. (I do love esoterica but it should generally be in strange little places, not randomly strewn across the code base.) I will put together an issue and a PR for this new update for people to ruminate upon. It's not as elegant as the original "just swap the order" solution. I can't figure out where the compiler optimization settings are set for the project. Is it in visual studio or do I need to find some XML file or something?
|
Notably, the above code is actually inlined which might have broader positive impact. |
Funny enough, if you do write the At the end of the day, that code doesn't seem too different from calling |
This PR is a very small non-semantic change to change the code for comparing TextAttribute instances so that the members are compared in their "physical" order rather than in whatever order the original author chose.
The effect of this is to generate significantly better code for the comparisons. The out-of-order comparisons forced the compiler to load the first cache line, cherry pick the first word of it, then load the second cache line, cherry pick a part of it, and then proceed further along.
This led to another contributor being led to want to write code that used memcmp() to perform the comparison which is usually a sign that things have gone very very wrong. Fortunately this appears to be a simpler solution which gets the vc++ compiler at least to generate the right code.
I have not tried other compilers, only the 14.31.31103 toolkit.
There are other issues in PR #10566 that I'll stay away from but this is simple and straightforward. I also added a compile-time assertion in the header and some comments. I assume the comments are goodness; the static assertion may be a problem on other platforms, I cannot verify.
PR Checklist
Sorry I don't have anything more detailed than the above plus the code.
I looked at the generated code under cdb before making the fix and then after.