-
Notifications
You must be signed in to change notification settings - Fork 24
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
attempt at optimizing allocs in replace.c #142
attempt at optimizing allocs in replace.c #142
Conversation
This version passes the testsuite on my computer. @GitMensch You may want to test it on your example to measure the number of allocations. It's supposed to allocate less than the original implementation in gnucobol 3.1, as there is no allocation of intermediate lists. |
related to #75 |
Oops - leads to 4 compile-errors in NIST SM and additional
|
Oh - if possible (for any cases like this - where NIST fails but our internal does not): please add "the issue" for the current failure to the testsuite, as this ensures higher coverage there ("someday" we don't want to run NIST that often, but our coverage is definitely not there yet). |
I think the bug is fixed now, and I added some more optimizations that I would be interested to check their performance. About the freeing to perform, is there a function that is calling all the freeing functions on exit ? |
Yes, on different places, as long as you use the right malloc - which is possibly
Seems so - could you get a grasp what that triggered and add it to the internal testsuite, please?
Will check in 7 to 17 hours and report back ;-) Note: the amount of one- or two-liner static function... looks special. |
Again: much better (apart from the memory free part better than both 3.1.2 and 3.2
Numbers from valgrind:
with the flamegraph not showing the replace functions any more. Therefore I'd say - issue fixed, only needs the "additional" parts (check use of memory-functions, reformat, in-file documentation check; handling TODOs, Changelog, ideally testsuite, possibly minor NEWS entry) then looks good to go. For the format: - if (copy_repls->replace_list == NULL &&
- copy_repls->current_list == NULL &&
- replace_repls->replace_list == NULL &&
- replace_repls->current_list == NULL) {
- return cb_ppecho_direct (text, token);
- }
+ if (copy_repls->replace_list == NULL
+ && copy_repls->current_list == NULL
+ && replace_repls->replace_list == NULL
+ && replace_repls->current_list == NULL) {
+ return cb_ppecho_direct (text, token);
+ } It likely is useful to also compare the actual |
9f44da1
to
d210c6e
Compare
Great. I cleaned the PR with ChangeLog and NEWS sections. Allocations should also be correctly freed at the end. I did not add a new entry in the testsuite, as the bug was in the data-structure |
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.
The difference between the testsuite and the NIST tests came from a test in NIST that had a replacement longer than 8 tokens, which seems not to exist in our testsuite
Please add it (likely by adjusting one of the existing tests) - this way we ensure things like that are catched easier in the future.
I may do a last try for getting the numbers in this issue correct, both with and without REPLACE
later this evening.
comparison between a numeric DISPLAY variable to another or to a | ||
literal comparison between numeric DISPLAY or BCD variable to zero | ||
INSPECT CONVERTING (and "simple" INSPECT REPLACING), in general and | ||
especially if both from and to are constants | ||
|
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.
The old indent is strange, but I think it matches the one from previous versions. If this is the case then either leave it as-is or, potentially better, replace in both cases by indented extra list starting with *
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.
Looking at NEWS from 3.2 and earlier version, I think the former indent was wrong even for them.
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.
thank you for fixing all of these with an * iteration
d210c6e
to
7f60896
Compare
now with
The "simple" adjustment did work fine (one of each,. the second nearly globally), resulting in
... but I'm not sure if my more complex test program for |
* Add two fast paths that completely avoid the replacement machinery (these two fast paths were formerly present in 3.1); * Use a circular buffer instead of a list for the temporary queue of tokens in streams; * Do not reallocate tokens passed from the copy-replacing stream to the replace stream
7f60896
to
78ef11d
Compare
I added a test case for a long replacement (and a combinaison of COPY and REPLACE on the same tokens), that would trigger the same error as the NIST test. I am not sure what you mean by your complex program: except for the two fast paths (that were already present in 3.1.2), this PR does not change the behavior of the COPY/REPLACE, so anything that worked with 3.1.2 and 3.2 should also work with this one. |
I think so - as noted this is good to be checked in upstream. As also noted I do need to recheck the example I've created in any case. |
I am thinking about writing a blog post about all this (how we fixed the initial bug and how we optimized it to match the perf of 3.1.2), do you happen to have a flamegraph of the final version also ? It could make a nice illustration of the evolution of performances during the work... |
The recordings for the flamegraph were taken by |
Thanks ! Is |
No chance. But I can share that the file is generated by Oracle Pro*COB from an (also generated) file handling SQL. |
Merged in SVN ! |
Well done. If you write that blog entry please drop a note in the discussion boards under GnuCOBOL. Note: while we've inspected the preprocessing here I've worked this week on the parsing speed and memory usage, especially for source files with lots of FILLERs as seen especially in generated programs and EXEC SQL preprocessed ones (speed inspected with perf/Hotspot, memory usage with Heaptrack) and hope to commit this soon as well. ... actually I hope to commit anything of the 95% stuff laying around, those tend to pile up. |
There are two steps to remove allocations: