make assertion conditions only run if enable asserts is switched on #1213
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.
One current issue with assertions in skulpt is that, while they don't throw assertion errors the condition is still evaluated
Some conditions are slower than others and so this might then cause a performance issue on hot code.
There are a couple of solutions for this that I can see.
1 would have the biggest win performance wise.
This pr does option 2 and replaces all
Sk.asserts.assert
condition statement with an arrow functionthe advantage is that the assert condition is only evaluated in dev mode and quicker
(if enable_asserts)
condition is evaluated instead.So something like
becomes
It also means that those using skulpt can turn on and off assertion statements as they like just using the
min.js
fileThey can just do
Sk.asserts.ENABLE_ASSERTS = true
rather than worry about different build options.It could potentially become one of the many undocumented
configure
arguments.