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

Speedups by avoiding inner classes #616

Merged
merged 2 commits into from
Oct 9, 2016
Merged

Conversation

poke1024
Copy link
Contributor

@poke1024 poke1024 commented Oct 7, 2016

Turns out that, at least in CPython, declaring classes inside functions is quite slow.

Running x = Range[50000]; First[Timing[Position[x, 10000]]] without this PR gives 1.16326, with this PR, it gives 0.461211. This is only due to one inner class definition.

Running the profiler, one actually sees Python's class build function popping up. So this PR moves inner classes out of functions at several places.

Copy link
Member

@sn6uv sn6uv left a comment

Choose a reason for hiding this comment

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

Looks good. I'm not sure about is_free though.

return True
else:
return expr.head.is_free(form, evaluation) and all(
leaf.is_free(form, evaluation) for leaf in expr.leaves)
Copy link
Member

Choose a reason for hiding this comment

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

is this function related to the change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot to hook this up. It's done now. I needed to move this function into patterns.py as the declaration of _StopGeneratorBaseExpressionIsFree needs StopGenerator which cannot be imported into core.expression.py as patterns.py depends on core.expression.py.

@sn6uv sn6uv merged commit d4912a1 into mathics:master Oct 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants