-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
builtin: fix runes.to_upper() (fix #22742) #22755
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent!
The change is nice, but unfortunately it affects Here are some comparisons between master and it, for
I've managed to reduce the .C size expansion a bit, by renaming Can we move the new versions, that require that table, outside of |
Does the size of the generated C file really matter that much? I don't usually pay any attention at all the the size of the .c files. I am more interested in the speed of the final code than the size of the intermediate steps. If it also affects the size of the final executable, that's not too big a deal right now, either. At some point, we will have better unused code deletion, which will help tremendously. |
Yes, it does matter, because it slows down compilation for short programs. |
Ideally yes. Pragmatically, it does increase the size (and slows down compilation) right now. |
You could say, that features like this, can serve as motivators for improving the code generation, as a second order effect, and you will be right 🤷🏻♂️ . |
The speed of the final code (at runtime) is not affected much - the size is increased mainly by the new const table for the rune rules. |
Here is a small comparison while compiling/running tests, between master and the PR here.
|
I also tried testing with (for what is worth, the new compiler version is slightly faster in that particular situation, compared to the version on master, even though both produce bigger binaries) |
On the other hand, this PR does fix the correctness of the methods, and one can argue, that is more important, compared to the increased resources needed for compilation and storage. |
I wonder if we can compress the rule table somehow 🤔 . |
That's why I think it should be moved to a On the other hand Go's string.ToUpper() imports |
Don't see why not. Make it a fixed array of fixed arrays of 5 ints. Slightly more complex code to deal with it, but it removes the overhead of all the It'll load faster, as well. |
I'm fine with making |
The table is ~2.3KB when compressed with xz, so there is a lot of redundancy in it. Before compressing, the .c delta for the |
Turning it into a fixed array (without restructuring into a flat array), did not work (I hit a cgen error edge case, which perhaps needs a separate issue). |
A flat array of just integers works fine, and reduces the overhead (compared to master, for hello_world) a lot:
|
|
As a bonus, the flat fixed array of ints, is initialized statically, not in |
Hm, if the problem is the size of the .c file, then why not have the compiler generate a .c file for each module? |
Flat fixed array is even better, though it makes the code even more interesting, but pretty standard for C-style programming. |
… to a flat fixed array of ints, to reduce overhead
^ that is with the flat fixed array. The compiletime and runtime overhead is now smaller. |
c0180b1
to
0bfb5e3
Compare
That is planned too (as an extension of I.e. you will get a smaller cost for the C compilation with The overhead of the generated binary at the end remains though even with |
Just tested
on the PR:
i.e. for me, the full test suite is still 10% slower now :-| . |
Still not that bad, considering the CI is what mainly runs |
Yes, and after re-running it again, I got a much closer result (+ ~2% overhead) ... Also some of the tests do network ops (i.e. high variability of the runtime), so the diff is not so bad after all, and it can be optimized later, after merging. |
I'll wait till the full CI passes here (because of the unsafe{} pointer arithmetic involved in the latest commit), then merge it. |
I think also that some of the overhead, can be explained not just by the increased .c file size by the new table, but also by the change to string.to_upper and string.to_lower to use a linear scan for non ASCII characters, and then the new rune based implementation to handle the non utf8 strings. The compiler may have to be changed, to selectively use a .to_upper_ascii and .to_lower_ascii methods, that will work as before, to avoid the non ASCII check completely (since we do not allow non ASCII characters for the identifiers/keywords etc) |
@spytheman I think we can get rid of the to_title item and shrink it. |
There were some entries, for which the upper offset was != than the title one:
They could be handled separately in |
hm, interesting ... tcc can not handle const integer values, used in const fixed array inits, failing with: typedef int Array_fixed_int_3 [3];
const int _const_ul = -3;
Array_fixed_int_3 _const_abc = {0, 1, _const_ul};
|
… for translated_const_fixed_array.vv
@spytheman Thank you very much for doing a lot of optimization! |
This PR fix runes.to_upper() (fix #22742).