You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(Apologise for the duplication - accidentally created the ticket from the wrong GH account)
Describe the bug
When compiled to WASM (wasm-pack --debug), the parser exceeds the call stack when fed certain input. I presumed it was getting stuck in an infinite recursion loop, but after compiling the exact same code in release mode, the issue vanished.
This implies that the root cause is that, in debug mode, the parser is prone to overflowing the stack simply due to being very recursive in its implementation.
To Reproduce
This is the minimal Rust code I found that reproduces the bug:
#[wasm_bindgen]
pub fn fail_case() {
let src = r#"
const a = function () {
b((c = d([])))
}
"#;
let context = &mut boa_engine::Context::builder().build().unwrap();
let source = boa_engine::Source::from_bytes(src);
let _module = boa_engine::Module::parse(source, None, context).unwrap();
}
Compiling to WASM and calling from JS in Chrome yields this stack trace:
Expected behavior
Successful parse without a stack overflow
Build environment (please complete the following information):
@jasonwilliams Is anyone actively looking into this issue? If not, I can take a look at the current parser implementation and see if there's any quick wins or what an ideal solution might look like.
@jasonwilliams Is anyone actively looking into this issue? If not, I can take a look at the current parser implementation and see if there's any quick wins or what an ideal solution might look like.
No one is looking at this, so yes we would be grateful if you can.
It looks like many expressions go through the same path which generates a deep stack:
This is actually following the spec, so it’s correct behaviour but not performant.
I think this could be flattened down to a loop instead. I don’t know for sure if this is the same issue you’re seeing, so don’t take my word for this, I know it’s the cause of the linked issue.
Please report back here on any findings, we can most likely help with any direction.
@Rafferty97 Hi, are you currently solving this issue?
I have sketched out a possible solution that should prevent stack overflows in the parser entirely, but I assume it would likely require pretty much changes. So if you are already working on this — then ok, go ahead.
@jasonwilliams
However, in case if nobody is actively dealing with the issue rn, I would like to discuss the approach with someone who will be reviewing it(who should I tag in that case?), because of the amount of expected changes and it's similarity it would be better to adjust the solution on the start.
@Nikita-str I think the best strategy would be to open a new issue with your idea sketched out, then you can link to that if you had a draft PR. But an issue is the best starting point because we could discuss in that.
If you wanted real time discussion we are all on the Matrix / Discord chat and you can ping us there.
Meanwhile, how important is parser performance?
Very
Is it ok to degrade it, for example, 2 times? 1.5?
I don’t think that would be acceptable, but I’m interested in what ideas you have in mind. Maybe we can find some solution that doesn’t kill performance so much.
@Rafferty97 Hi, are you currently solving this issue? I have sketched out a possible solution that should prevent stack overflows in the parser entirely, but I assume it would likely require pretty much changes. So if you are already working on this — then ok, go ahead.
@jasonwilliams However, in case if nobody is actively dealing with the issue rn, I would like to discuss the approach with someone who will be reviewing it(who should I tag in that case?), because of the amount of expected changes and it's similarity it would be better to adjust the solution on the start.
@Nikita-str Apologies for the delayed reply. No, I haven't had the time to actively work on this unfortunately, so please feel free to take it off my hands if you think you've got a solution in mind.
Activity
jasonwilliams commentedon Jun 24, 2025
Also related: #1402
Rafferty97 commentedon Jun 25, 2025
@jasonwilliams Is anyone actively looking into this issue? If not, I can take a look at the current parser implementation and see if there's any quick wins or what an ideal solution might look like.
nekevss commentedon Jun 25, 2025
I don't think anyone is currently looking into it. Feel free to take a look! 😄
jasonwilliams commentedon Jun 25, 2025
No one is looking at this, so yes we would be grateful if you can.
It looks like many expressions go through the same path which generates a deep stack:
This is actually following the spec, so it’s correct behaviour but not performant.
I think this could be flattened down to a loop instead. I don’t know for sure if this is the same issue you’re seeing, so don’t take my word for this, I know it’s the cause of the linked issue.
Please report back here on any findings, we can most likely help with any direction.
Nikita-str commentedon Jun 28, 2025
@Rafferty97 Hi, are you currently solving this issue?
I have sketched out a possible solution that should prevent stack overflows in the parser entirely, but I assume it would likely require pretty much changes. So if you are already working on this — then ok, go ahead.
@jasonwilliams
However, in case if nobody is actively dealing with the issue rn, I would like to discuss the approach with someone who will be reviewing it(who should I tag in that case?), because of the amount of expected changes and it's similarity it would be better to adjust the solution on the start.
Nikita-str commentedon Jun 28, 2025
Meanwhile, how important is parser performance? Is it ok to degrade it, for example, 2 times? 1.5?
Another question, why
boa_parser::TokenParser<R>isSized? Is this done on purpose? For what?jasonwilliams commentedon Jun 28, 2025
@Nikita-str I think the best strategy would be to open a new issue with your idea sketched out, then you can link to that if you had a draft PR. But an issue is the best starting point because we could discuss in that.
If you wanted real time discussion we are all on the Matrix / Discord chat and you can ping us there.
Very
I don’t think that would be acceptable, but I’m interested in what ideas you have in mind. Maybe we can find some solution that doesn’t kill performance so much.
Rafferty97 commentedon Jul 9, 2025
@Nikita-str Apologies for the delayed reply. No, I haven't had the time to actively work on this unfortunately, so please feel free to take it off my hands if you think you've got a solution in mind.