-
-
Notifications
You must be signed in to change notification settings - Fork 411
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
Implement runtime limits for loops #2857
Conversation
Test262 conformance changes
|
Codecov Report
@@ Coverage Diff @@
## main #2857 +/- ##
==========================================
- Coverage 51.77% 51.24% -0.53%
==========================================
Files 427 430 +3
Lines 42610 42714 +104
==========================================
- Hits 22061 21890 -171
- Misses 20549 20824 +275
|
I have not done a complete review, but I saw the new opcodes and though; can we not keep the limit counts in the |
Thanks for the suggestion! It's probably the best place to put it! I realized this when I was half way through implementing the initial POC 😆 |
b43fc62
to
b13e9a0
Compare
While working on #2857 I discovered that while generating the bytecode for `do-while` loops we were emitting an orphan `LoopContinue` that is never executed, which was preventing the error to be thrown when max loop iteration is reached. This can more easily be identified with it's flowgraph : (`do { 1; } while(0) `) Main: <details> <img src="https://user-images.githubusercontent.com/8566042/233908011-247313bc-6435-4622-8ecb-f469d9eaf850.png"> </details> With this PR: <details> <img src="https://user-images.githubusercontent.com/8566042/233908030-3552636e-f09c-4c5e-8c7c-1ecfa0024dfe.png"> </details>
983965b
to
b108f29
Compare
ca6cc9b
to
8caeba5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good.
Can we set the stack_size_limit
to 1024
(or another value that currently works) in our tests and the boa_tester? That way we use the feature ourselves and we may also catch bugs that spill the stack.
It set to |
Does it affect performance? If it's negligible, I would say we should use an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm missing a test, where we run a loop without limits for 10 iterations (as an example) and it works, then we set the limit to 5 iterations, try to run it again, and check that we get the error.
Loop { | ||
/// This is used to keep track of how many iterations a loop has done. | ||
#[cfg(feature = "runtime-limits")] | ||
iteration_count: u64, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious on what your thoughts might be about setting this as a u16
vs. u64
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I set it because I felt like that was too restrictive [0, 65535]
for u16
, u32
with [0, 4294967295]
is better but it is possible to iterate over it (takes like a second on node with jitting), but u64
should be more than enough for everyone [0, 18446744073709551615]
:D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😆 I'd agree that u64 is more than enough.
I mostly brought it up because of how large u64 is. It may be worth keeping track or maybe getting a poll/input to see if people are setting runtime limits past a certain point and see if we should lower to a u32
or something. But that could just be me being overly concerned and thinking about it completely wrong.
Yes, ran the benchmarks locally and it wasn't showing that it had any effect on performance, and it makes sense to allow limiting by default. |
8caeba5
to
8e8a83d
Compare
Added an example in I stuck with using With these changes the limit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me :) check my suggestions and see if they make sense
8e8a83d
to
4ccc5e6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks just about good to me 😄
55f9a66
to
4f15682
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice addition!
Depends on #2866
Related to #2350
This PR adds runtime limits on all loops (
while
,do..while
,for
,for-in
, andfor-of
) that can be controlled at runtime,this is feature gated under the"runtime-limits"
feature flag because introduces some minor overhead due to needed iteration tracking.By default when the feature is enabled it is set to
u64::MAX
, which means no runtime limitIt changes the following:
RuntimeLimits
that contains the runtime limits.$boa.limits.loop
getter and setter for easier testing.Setting the limit from rust:
Or using the
$boa
object for debugging: