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

Improve performance of encodeNestedLists #453

Merged
merged 4 commits into from
Oct 12, 2020

Conversation

daneelsan
Copy link
Collaborator

@daneelsan daneelsan commented Oct 12, 2020

Changes

Examples

In[]:= rules = {{{a_, b_}, {a_, c_}, {a_, d_}} :> 
    Module[{$0, $1, $2}, {{$0, $1}, {$1, $2}, {$2, $0}, {$0, $2}, \
{$2, $1}, {$1, $0}, {$0, b}, {$1, c}, {$2, d}, {b, $2}, {d, $0}}]};
AbsoluteTiming[set = SetReplace[{{0, 0}, {0, 0}, {0, 0}}, rules, 100]] // First
AbsoluteTiming[SetReplace[set, rules]][[1]]

Out[]= 0.052426
Out[]= 0.026598

This change is Reviewable

@daneelsan daneelsan added the weed Something isn't working label Oct 12, 2020
@daneelsan daneelsan requested a review from maxitg October 12, 2020 05:13
@daneelsan daneelsan self-assigned this Oct 12, 2020
@daneelsan
Copy link
Collaborator Author

daneelsan commented Oct 12, 2020

This improves this example in the documentation, but I'm not sure how to rework that part:

In[]:= AbsoluteTiming[WolframModel[{{{0}} -> {{0}, {0}, {0}}, {{0}, {0}, {0}} -> {{0}}}, {{0}}, <|"MaxEvents" -> 30|>, Method -> "LowLevel"]] // First
Out[]= 1.88309

In[]:= AbsoluteTiming[WolframModel[{{{0}} -> {{0}, {0}, {0}}, {{0}, {0}, {0}} -> {{0}}}, {{0}}, <|"MaxEvents" -> 30|>, Method -> "Symbolic"]] // First
Out[]= 0.019555

Copy link
Owner

@maxitg maxitg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example from the documentation is about a completely separate issue (#31). I don't think it really needs changing at all, but we can update the timing since it has probably improved due to this and @aokellermann's optimizations.

Reviewed 2 of 2 files at r1.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @daneelsan)


Kernel/setSubstitutionSystem$cpp.m, line 80 at r1 (raw file):

(* This format is used to pass both rules and set data into libSetReplace over LibraryLink *)

encodeNestedLists[l_List] := Flatten @ {Length @ l, encodeNestedLists /@ l}

Please use more descriptive variable names, e.g., l -> list and a -> arg.


Tests/performance.wlt, line 33 at r1 (raw file):

              1000]],
            List,
            TimeConstraint -> 10,

This test actually has nothing to do with this (the initial state is small here). The reason the time constraint is so large here is that the test does not fail randomly due to fluctuations in performance and would only fail if it was catastrophically slower than before.

@daneelsan daneelsan requested a review from maxitg October 12, 2020 19:58
Copy link
Collaborator Author

@daneelsan daneelsan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @maxitg)


Kernel/setSubstitutionSystem$cpp.m, line 80 at r1 (raw file):

Previously, maxitg (Max Piskunov) wrote…

Please use more descriptive variable names, e.g., l -> list and a -> arg.

Done.


Tests/performance.wlt, line 33 at r1 (raw file):

Previously, maxitg (Max Piskunov) wrote…

This test actually has nothing to do with this (the initial state is small here). The reason the time constraint is so large here is that the test does not fail randomly due to fluctuations in performance and would only fail if it was catastrophically slower than before.

Reverted the changes I made there.

Copy link
Owner

@maxitg maxitg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! 🚀

Reviewed 2 of 2 files at r2.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@daneelsan daneelsan merged commit e3192ed into master Oct 12, 2020
@daneelsan daneelsan deleted the weedwhack/46/slow-passing-inputs-lowlevel branch October 12, 2020 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
weed Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Slow passing inputs to C++ code
2 participants