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
WIP: benchmarking various tree representations and linear allocator #1598
Open
certik
wants to merge
70
commits into
symengine:master
Choose a base branch
from
certik:wip_alloc
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hi, I've run clang-format and found that the code needs formatting. To use the commit you can do
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This uses the new (fast) parser to parse a long expression into various tree representations. One can switch between them in
symengine/parser/parser_stype.h
.sem1.h
: SymEnginesem2.h
: integer arithmetic (the fastest non-trivial benchmark, as the "maximum performance we can hope to achieve"sem3.h
: simple empty structsem4.h
: C union style structssem5.h
: C++ inheritance modelsem6.h
: C++ inheritance model and unique pointer (similar to SymEngine)sem7.h
: C++17 std::variant based polymorphismFor
sem1
,sem4
,sem6
andsem7
I also implemented a custom linear allocator insymengine/parser/alloc.h
. It provides significant speedup for all representations except SymEngine (which gets slower --- I wonder if that's because STL data structures still use the default C++ allocator).The
sem4
andsem6
are about the same speed.sem6
is what SymEngine uses. SymEngine actually uses RCP pointers, but when I "disable" the ref counting, I don't observe much of a speedup. I think it's fast to construct. So thesem6
design is close to optimal. SymEngine itself is about twice slower, but that's because SymEngine does the complicated canonicalization, which is needed for computer algebra.It's interesting that
sem7
is consistently about 10% slower thansym6
, with or without the allocator. The construction is slower, and then the visitation is about 2x slower... Given thatstd::variant
is slow to compile and gives terrible error messages (pages and pages of template errors) when I made a mistake instd::visit
, I would say, it's much better not to use it.I am doing this investigation to figure out the best representation for AST in LFortran, where I need to parse the file and quickly construct and AST. So the linear allocator might work: it simply deallocates all the memory at once. However, some of this might speedup SymEngine also. I think there might be a way to use a better allocator, but I think I need to play with the STL also.