Skip to content

Commit

Permalink
Improve JsString performance (#2042)
Browse files Browse the repository at this point in the history
It changes the following:

- The current `JsString` implementation has a lot of duplicate heap allocations. For static strings, `JsString` only needs to store the index of `CONSTANTS_ARRAY`. ~~I let `JsString` can store pointer to heap or static area. The two are distinguished by the first bit. (This implementation is rough, maybe we should put flag into `Inner`, like [arcstr](https://github.com/thomcc/arcstr/blob/70ba2fac19d3efe8d2e0231daaf74f9987c04b8a/src/arc_str.rs#L751-L757))~~
- I also added more string constants, which are always used.
  • Loading branch information
YXL76 authored and Razican committed Jun 8, 2022
1 parent b6488ae commit 655501e
Show file tree
Hide file tree
Showing 2 changed files with 518 additions and 68 deletions.
4 changes: 2 additions & 2 deletions boa_engine/src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ impl JsBigInt {
let inner = if n > 0 {
x.inner.as_ref().clone().shr(n as usize)
} else {
x.inner.as_ref().clone().shl(n.abs() as usize)
x.inner.as_ref().clone().shl(n.unsigned_abs())
};

Ok(Self::new(inner))
Expand All @@ -195,7 +195,7 @@ impl JsBigInt {
let inner = if n > 0 {
x.inner.as_ref().clone().shl(n as usize)
} else {
x.inner.as_ref().clone().shr(n.abs() as usize)
x.inner.as_ref().clone().shr(n.unsigned_abs())
};

Ok(Self::new(inner))
Expand Down
Loading

0 comments on commit 655501e

Please sign in to comment.