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

WIP: benchmarking various tree representations and linear allocator #1598

Open
wants to merge 70 commits into
base: master
Choose a base branch
from

Conversation

certik
Copy link
Contributor

@certik certik commented Aug 8, 2019

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: SymEngine
  • sem2.h: integer arithmetic (the fastest non-trivial benchmark, as the "maximum performance we can hope to achieve"
  • sem3.h: simple empty struct
  • sem4.h: C union style structs
  • sem5.h: C++ inheritance model
  • sem6.h: C++ inheritance model and unique pointer (similar to SymEngine)
  • sem7.h: C++17 std::variant based polymorphism

For sem1, sem4, sem6 and sem7 I also implemented a custom linear allocator in symengine/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 and sem6 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 the sem6 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 than sym6, with or without the allocator. The construction is slower, and then the visitation is about 2x slower... Given that std::variant is slow to compile and gives terrible error messages (pages and pages of template errors) when I made a mistake in std::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.

@isuruf-bot
Copy link

Hi,

I've run clang-format and found that the code needs formatting.
Here's a commit that fixes this. isuruf-bot@ebd35d0

To use the commit you can do

curl -o format.diff https://github.com/isuruf-bot/symengine/commit/ebd35d0f302c0ab9cc9747c11f1ba6c3d1fea705.diff
git apply format.diff

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.

None yet

2 participants