Browse Source

use with_capacity to reduce re-allocations fixes #3896 (#3961)

* use with_capacity to reduce allocations

* Update to use const generics over runtime param

* add comment above with_capacity

* - move OWN_PROPS
- add profiling marks in more places

* use const in trait instead
pull/4026/head
Jason Williams 2 months ago committed by GitHub
parent
commit
d8ec97c85f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      core/engine/src/builtins/array/mod.rs
  2. 2
      core/engine/src/builtins/array_buffer/mod.rs
  3. 2
      core/engine/src/builtins/array_buffer/shared.rs
  4. 2
      core/engine/src/builtins/async_function/mod.rs
  5. 2
      core/engine/src/builtins/async_generator_function/mod.rs
  6. 2
      core/engine/src/builtins/bigint/mod.rs
  7. 2
      core/engine/src/builtins/boolean/mod.rs
  8. 12
      core/engine/src/builtins/builder.rs
  9. 2
      core/engine/src/builtins/dataview/mod.rs
  10. 2
      core/engine/src/builtins/date/mod.rs
  11. 2
      core/engine/src/builtins/error/aggregate.rs
  12. 2
      core/engine/src/builtins/error/eval.rs
  13. 2
      core/engine/src/builtins/error/mod.rs
  14. 2
      core/engine/src/builtins/error/range.rs
  15. 2
      core/engine/src/builtins/error/reference.rs
  16. 2
      core/engine/src/builtins/error/syntax.rs
  17. 2
      core/engine/src/builtins/error/type.rs
  18. 2
      core/engine/src/builtins/error/uri.rs
  19. 2
      core/engine/src/builtins/function/mod.rs
  20. 2
      core/engine/src/builtins/generator_function/mod.rs
  21. 2
      core/engine/src/builtins/intl/collator/mod.rs
  22. 2
      core/engine/src/builtins/intl/date_time_format.rs
  23. 2
      core/engine/src/builtins/intl/list_format/mod.rs
  24. 2
      core/engine/src/builtins/intl/locale/mod.rs
  25. 2
      core/engine/src/builtins/intl/number_format/mod.rs
  26. 2
      core/engine/src/builtins/intl/plural_rules/mod.rs
  27. 2
      core/engine/src/builtins/intl/segmenter/mod.rs
  28. 2
      core/engine/src/builtins/map/mod.rs
  29. 7
      core/engine/src/builtins/mod.rs
  30. 2
      core/engine/src/builtins/number/mod.rs
  31. 2
      core/engine/src/builtins/object/mod.rs
  32. 2
      core/engine/src/builtins/promise/mod.rs
  33. 2
      core/engine/src/builtins/proxy/mod.rs
  34. 2
      core/engine/src/builtins/regexp/mod.rs
  35. 2
      core/engine/src/builtins/set/mod.rs
  36. 2
      core/engine/src/builtins/string/mod.rs
  37. 2
      core/engine/src/builtins/symbol/mod.rs
  38. 2
      core/engine/src/builtins/temporal/duration/mod.rs
  39. 2
      core/engine/src/builtins/temporal/instant/mod.rs
  40. 2
      core/engine/src/builtins/temporal/plain_date/mod.rs
  41. 2
      core/engine/src/builtins/temporal/plain_date_time/mod.rs
  42. 2
      core/engine/src/builtins/temporal/plain_month_day/mod.rs
  43. 2
      core/engine/src/builtins/temporal/plain_time/mod.rs
  44. 2
      core/engine/src/builtins/temporal/plain_year_month/mod.rs
  45. 2
      core/engine/src/builtins/temporal/zoned_date_time/mod.rs
  46. 2
      core/engine/src/builtins/typed_array/builtin.rs
  47. 2
      core/engine/src/builtins/typed_array/mod.rs
  48. 2
      core/engine/src/builtins/weak/weak_ref.rs
  49. 2
      core/engine/src/builtins/weak_map/mod.rs
  50. 2
      core/engine/src/builtins/weak_set/mod.rs
  51. 3
      core/engine/src/context/icu.rs
  52. 1
      core/engine/src/context/mod.rs
  53. 2
      core/engine/src/module/loader.rs
  54. 21
      core/engine/src/object/shape/property_table.rs
  55. 3
      core/engine/src/object/shape/shared_shape/mod.rs
  56. 1
      core/engine/src/vm/mod.rs

3
core/engine/src/builtins/array/mod.rs

@ -190,6 +190,9 @@ impl BuiltInObject for Array {
} }
impl BuiltInConstructor for Array { impl BuiltInConstructor for Array {
const P: usize = 41;
const SP: usize = 5;
const LENGTH: usize = 1; const LENGTH: usize = 1;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =

2
core/engine/src/builtins/array_buffer/mod.rs

@ -374,6 +374,8 @@ impl BuiltInObject for ArrayBuffer {
} }
impl BuiltInConstructor for ArrayBuffer { impl BuiltInConstructor for ArrayBuffer {
const P: usize = 9;
const SP: usize = 2;
const LENGTH: usize = 1; const LENGTH: usize = 1;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =

2
core/engine/src/builtins/array_buffer/shared.rs

@ -155,6 +155,8 @@ impl BuiltInObject for SharedArrayBuffer {
impl BuiltInConstructor for SharedArrayBuffer { impl BuiltInConstructor for SharedArrayBuffer {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 6;
const SP: usize = 1;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::shared_array_buffer; StandardConstructors::shared_array_buffer;

2
core/engine/src/builtins/async_function/mod.rs

@ -52,6 +52,8 @@ impl BuiltInObject for AsyncFunction {
impl BuiltInConstructor for AsyncFunction { impl BuiltInConstructor for AsyncFunction {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 1;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::async_function; StandardConstructors::async_function;

2
core/engine/src/builtins/async_generator_function/mod.rs

@ -57,6 +57,8 @@ impl BuiltInObject for AsyncGeneratorFunction {
impl BuiltInConstructor for AsyncGeneratorFunction { impl BuiltInConstructor for AsyncGeneratorFunction {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 2;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::async_generator_function; StandardConstructors::async_generator_function;

2
core/engine/src/builtins/bigint/mod.rs

@ -65,6 +65,8 @@ impl BuiltInObject for BigInt {
impl BuiltInConstructor for BigInt { impl BuiltInConstructor for BigInt {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 3;
const SP: usize = 2;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::bigint; StandardConstructors::bigint;

2
core/engine/src/builtins/boolean/mod.rs

@ -51,6 +51,8 @@ impl BuiltInObject for Boolean {
impl BuiltInConstructor for Boolean { impl BuiltInConstructor for Boolean {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 2;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::boolean; StandardConstructors::boolean;

12
core/engine/src/builtins/builder.rs

@ -135,6 +135,9 @@ impl ApplyToObject for OrdinaryObject {
fn apply_to(self, _: &JsObject) {} fn apply_to(self, _: &JsObject) {}
} }
// The number of properties that are always present in a standard constructor. See build method
const OWN_PROPS: usize = 3;
/// Builder for creating built-in objects, like `Array`. /// Builder for creating built-in objects, like `Array`.
/// ///
/// The marker `ObjectType` restricts the methods that can be called depending on the /// The marker `ObjectType` restricts the methods that can be called depending on the
@ -528,6 +531,7 @@ impl<'ctx> BuiltInBuilder<'ctx, OrdinaryObject> {
} }
impl<'ctx> BuiltInBuilder<'ctx, Callable<Constructor>> { impl<'ctx> BuiltInBuilder<'ctx, Callable<Constructor>> {
/// Create a new builder for a constructor function setting the properties ahead of time for optimizations (less reallocations)
pub(crate) fn from_standard_constructor<SC: BuiltInConstructor>( pub(crate) fn from_standard_constructor<SC: BuiltInConstructor>(
realm: &'ctx Realm, realm: &'ctx Realm,
) -> BuiltInConstructorWithPrototype<'ctx> { ) -> BuiltInConstructorWithPrototype<'ctx> {
@ -537,11 +541,11 @@ impl<'ctx> BuiltInBuilder<'ctx, Callable<Constructor>> {
function: SC::constructor, function: SC::constructor,
name: js_string!(SC::NAME), name: js_string!(SC::NAME),
length: SC::LENGTH, length: SC::LENGTH,
object_property_table: PropertyTableInner::default(), object_property_table: PropertyTableInner::with_capacity(SC::SP + OWN_PROPS),
object_storage: Vec::default(), object_storage: Vec::with_capacity(SC::SP + OWN_PROPS),
object: constructor.constructor(), object: constructor.constructor(),
prototype_property_table: PropertyTableInner::default(), prototype_property_table: PropertyTableInner::with_capacity(SC::P),
prototype_storage: Vec::default(), prototype_storage: Vec::with_capacity(SC::P),
prototype: constructor.prototype(), prototype: constructor.prototype(),
__proto__: Some(realm.intrinsics().constructors().function().prototype()), __proto__: Some(realm.intrinsics().constructors().function().prototype()),
inherits: Some(realm.intrinsics().constructors().object().prototype()), inherits: Some(realm.intrinsics().constructors().object().prototype()),

2
core/engine/src/builtins/dataview/mod.rs

@ -167,6 +167,8 @@ impl BuiltInObject for DataView {
impl BuiltInConstructor for DataView { impl BuiltInConstructor for DataView {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 24;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::data_view; StandardConstructors::data_view;

2
core/engine/src/builtins/date/mod.rs

@ -185,6 +185,8 @@ impl BuiltInObject for Date {
impl BuiltInConstructor for Date { impl BuiltInConstructor for Date {
const LENGTH: usize = 7; const LENGTH: usize = 7;
const P: usize = 47;
const SP: usize = 3;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::date; StandardConstructors::date;

2
core/engine/src/builtins/error/aggregate.rs

@ -52,6 +52,8 @@ impl BuiltInObject for AggregateError {
impl BuiltInConstructor for AggregateError { impl BuiltInConstructor for AggregateError {
const LENGTH: usize = 2; const LENGTH: usize = 2;
const P: usize = 2;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::aggregate_error; StandardConstructors::aggregate_error;

2
core/engine/src/builtins/error/eval.rs

@ -54,6 +54,8 @@ impl BuiltInObject for EvalError {
impl BuiltInConstructor for EvalError { impl BuiltInConstructor for EvalError {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 2;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::eval_error; StandardConstructors::eval_error;

2
core/engine/src/builtins/error/mod.rs

@ -154,6 +154,8 @@ impl BuiltInObject for Error {
impl BuiltInConstructor for Error { impl BuiltInConstructor for Error {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 2;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::error; StandardConstructors::error;

2
core/engine/src/builtins/error/range.rs

@ -52,6 +52,8 @@ impl BuiltInObject for RangeError {
impl BuiltInConstructor for RangeError { impl BuiltInConstructor for RangeError {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 2;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::range_error; StandardConstructors::range_error;

2
core/engine/src/builtins/error/reference.rs

@ -51,6 +51,8 @@ impl BuiltInObject for ReferenceError {
impl BuiltInConstructor for ReferenceError { impl BuiltInConstructor for ReferenceError {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 2;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::reference_error; StandardConstructors::reference_error;

2
core/engine/src/builtins/error/syntax.rs

@ -54,6 +54,8 @@ impl BuiltInObject for SyntaxError {
impl BuiltInConstructor for SyntaxError { impl BuiltInConstructor for SyntaxError {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 2;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::syntax_error; StandardConstructors::syntax_error;

2
core/engine/src/builtins/error/type.rs

@ -60,6 +60,8 @@ impl BuiltInObject for TypeError {
impl BuiltInConstructor for TypeError { impl BuiltInConstructor for TypeError {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 2;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::type_error; StandardConstructors::type_error;

2
core/engine/src/builtins/error/uri.rs

@ -53,6 +53,8 @@ impl BuiltInObject for UriError {
impl BuiltInConstructor for UriError { impl BuiltInConstructor for UriError {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 2;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::uri_error; StandardConstructors::uri_error;

2
core/engine/src/builtins/function/mod.rs

@ -356,6 +356,8 @@ impl BuiltInObject for BuiltInFunctionObject {
impl BuiltInConstructor for BuiltInFunctionObject { impl BuiltInConstructor for BuiltInFunctionObject {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 7;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::function; StandardConstructors::function;

2
core/engine/src/builtins/generator_function/mod.rs

@ -62,6 +62,8 @@ impl BuiltInObject for GeneratorFunction {
impl BuiltInConstructor for GeneratorFunction { impl BuiltInConstructor for GeneratorFunction {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 2;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::generator_function; StandardConstructors::generator_function;

2
core/engine/src/builtins/intl/collator/mod.rs

@ -188,6 +188,8 @@ impl BuiltInObject for Collator {
impl BuiltInConstructor for Collator { impl BuiltInConstructor for Collator {
const LENGTH: usize = 0; const LENGTH: usize = 0;
const P: usize = 3;
const SP: usize = 1;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::collator; StandardConstructors::collator;

2
core/engine/src/builtins/intl/date_time_format.rs

@ -82,6 +82,8 @@ impl BuiltInObject for DateTimeFormat {
impl BuiltInConstructor for DateTimeFormat { impl BuiltInConstructor for DateTimeFormat {
const LENGTH: usize = 0; const LENGTH: usize = 0;
const P: usize = 0;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::date_time_format; StandardConstructors::date_time_format;

2
core/engine/src/builtins/intl/list_format/mod.rs

@ -83,6 +83,8 @@ impl BuiltInObject for ListFormat {
impl BuiltInConstructor for ListFormat { impl BuiltInConstructor for ListFormat {
const LENGTH: usize = 0; const LENGTH: usize = 0;
const P: usize = 4;
const SP: usize = 1;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::list_format; StandardConstructors::list_format;

2
core/engine/src/builtins/intl/locale/mod.rs

@ -157,6 +157,8 @@ impl BuiltInObject for Locale {
impl BuiltInConstructor for Locale { impl BuiltInConstructor for Locale {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 14;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::locale; StandardConstructors::locale;

2
core/engine/src/builtins/intl/number_format/mod.rs

@ -173,6 +173,8 @@ impl BuiltInObject for NumberFormat {
impl BuiltInConstructor for NumberFormat { impl BuiltInConstructor for NumberFormat {
const LENGTH: usize = 0; const LENGTH: usize = 0;
const P: usize = 3;
const SP: usize = 1;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::number_format; StandardConstructors::number_format;

2
core/engine/src/builtins/intl/plural_rules/mod.rs

@ -83,6 +83,8 @@ impl BuiltInObject for PluralRules {
impl BuiltInConstructor for PluralRules { impl BuiltInConstructor for PluralRules {
const LENGTH: usize = 0; const LENGTH: usize = 0;
const P: usize = 4;
const SP: usize = 1;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::plural_rules; StandardConstructors::plural_rules;

2
core/engine/src/builtins/intl/segmenter/mod.rs

@ -119,6 +119,8 @@ impl BuiltInObject for Segmenter {
impl BuiltInConstructor for Segmenter { impl BuiltInConstructor for Segmenter {
const LENGTH: usize = 0; const LENGTH: usize = 0;
const P: usize = 3;
const SP: usize = 1;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::segmenter; StandardConstructors::segmenter;

2
core/engine/src/builtins/map/mod.rs

@ -108,6 +108,8 @@ impl BuiltInObject for Map {
impl BuiltInConstructor for Map { impl BuiltInConstructor for Map {
const LENGTH: usize = 0; const LENGTH: usize = 0;
const P: usize = 11;
const SP: usize = 2;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::map; StandardConstructors::map;

7
core/engine/src/builtins/mod.rs

@ -37,6 +37,7 @@ pub mod weak_set;
mod builder; mod builder;
use boa_macros::js_str; use boa_macros::js_str;
use boa_profiler::Profiler;
use builder::BuiltInBuilder; use builder::BuiltInBuilder;
#[cfg(feature = "annex-b")] #[cfg(feature = "annex-b")]
@ -157,6 +158,10 @@ pub(crate) trait BuiltInObject: IntrinsicObject {
/// ///
/// [built-in object]: https://tc39.es/ecma262/#sec-built-in-object /// [built-in object]: https://tc39.es/ecma262/#sec-built-in-object
pub(crate) trait BuiltInConstructor: BuiltInObject { pub(crate) trait BuiltInConstructor: BuiltInObject {
/// Const Generic `P` is the minimum storage capacity for the prototype's Property table.
const P: usize;
/// Const Generic `SP` is the minimum storage capacity for the object's Static Property table.
const SP: usize;
/// The amount of arguments this function object takes. /// The amount of arguments this function object takes.
const LENGTH: usize; const LENGTH: usize;
@ -304,6 +309,8 @@ impl Realm {
/// ///
/// [spec]: https://tc39.es/ecma262/#sec-setdefaultglobalbindings /// [spec]: https://tc39.es/ecma262/#sec-setdefaultglobalbindings
pub(crate) fn set_default_global_bindings(context: &mut Context) -> JsResult<()> { pub(crate) fn set_default_global_bindings(context: &mut Context) -> JsResult<()> {
let _timer =
Profiler::global().start_event("Builtins::set_default_global_bindings", "Builtins");
let global_object = context.global_object(); let global_object = context.global_object();
global_object.define_property_or_throw( global_object.define_property_or_throw(

2
core/engine/src/builtins/number/mod.rs

@ -108,6 +108,8 @@ impl BuiltInObject for Number {
impl BuiltInConstructor for Number { impl BuiltInConstructor for Number {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 6;
const SP: usize = 14;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::number; StandardConstructors::number;

2
core/engine/src/builtins/object/mod.rs

@ -150,6 +150,8 @@ impl BuiltInObject for OrdinaryObject {
impl BuiltInConstructor for OrdinaryObject { impl BuiltInConstructor for OrdinaryObject {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 11;
const SP: usize = 23;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::object; StandardConstructors::object;

2
core/engine/src/builtins/promise/mod.rs

@ -381,6 +381,8 @@ impl BuiltInObject for Promise {
impl BuiltInConstructor for Promise { impl BuiltInConstructor for Promise {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 4;
const SP: usize = 9;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::promise; StandardConstructors::promise;

2
core/engine/src/builtins/proxy/mod.rs

@ -106,6 +106,8 @@ impl BuiltInObject for Proxy {
impl BuiltInConstructor for Proxy { impl BuiltInConstructor for Proxy {
const LENGTH: usize = 2; const LENGTH: usize = 2;
const P: usize = 0;
const SP: usize = 1;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::proxy; StandardConstructors::proxy;

2
core/engine/src/builtins/regexp/mod.rs

@ -177,6 +177,8 @@ impl BuiltInObject for RegExp {
impl BuiltInConstructor for RegExp { impl BuiltInConstructor for RegExp {
const LENGTH: usize = 2; const LENGTH: usize = 2;
const P: usize = 19;
const SP: usize = 1;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::regexp; StandardConstructors::regexp;

2
core/engine/src/builtins/set/mod.rs

@ -109,6 +109,8 @@ impl BuiltInObject for Set {
impl BuiltInConstructor for Set { impl BuiltInConstructor for Set {
const LENGTH: usize = 0; const LENGTH: usize = 0;
const P: usize = 11;
const SP: usize = 1;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::set; StandardConstructors::set;

2
core/engine/src/builtins/string/mod.rs

@ -198,6 +198,8 @@ impl BuiltInObject for String {
impl BuiltInConstructor for String { impl BuiltInConstructor for String {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 36;
const SP: usize = 3;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::string; StandardConstructors::string;

2
core/engine/src/builtins/symbol/mod.rs

@ -186,6 +186,8 @@ impl BuiltInObject for Symbol {
impl BuiltInConstructor for Symbol { impl BuiltInConstructor for Symbol {
const LENGTH: usize = 0; const LENGTH: usize = 0;
const P: usize = 5;
const SP: usize = 15;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::symbol; StandardConstructors::symbol;

2
core/engine/src/builtins/temporal/duration/mod.rs

@ -201,6 +201,8 @@ impl IntrinsicObject for Duration {
impl BuiltInConstructor for Duration { impl BuiltInConstructor for Duration {
const LENGTH: usize = 0; const LENGTH: usize = 0;
const P: usize = 22;
const SP: usize = 1;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::duration; StandardConstructors::duration;

2
core/engine/src/builtins/temporal/instant/mod.rs

@ -127,6 +127,8 @@ impl IntrinsicObject for Instant {
impl BuiltInConstructor for Instant { impl BuiltInConstructor for Instant {
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 13;
const SP: usize = 4;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::instant; StandardConstructors::instant;

2
core/engine/src/builtins/temporal/plain_date/mod.rs

@ -241,6 +241,8 @@ impl IntrinsicObject for PlainDate {
impl BuiltInConstructor for PlainDate { impl BuiltInConstructor for PlainDate {
const LENGTH: usize = 3; const LENGTH: usize = 3;
const P: usize = 26;
const SP: usize = 2;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::plain_date; StandardConstructors::plain_date;

2
core/engine/src/builtins/temporal/plain_date_time/mod.rs

@ -298,6 +298,8 @@ impl IntrinsicObject for PlainDateTime {
impl BuiltInConstructor for PlainDateTime { impl BuiltInConstructor for PlainDateTime {
const LENGTH: usize = 3; const LENGTH: usize = 3;
const P: usize = 29;
const SP: usize = 2;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::plain_date_time; StandardConstructors::plain_date_time;

2
core/engine/src/builtins/temporal/plain_month_day/mod.rs

@ -185,6 +185,8 @@ impl IntrinsicObject for PlainMonthDay {
impl BuiltInConstructor for PlainMonthDay { impl BuiltInConstructor for PlainMonthDay {
const LENGTH: usize = 2; const LENGTH: usize = 2;
const P: usize = 5;
const SP: usize = 1;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::plain_month_day; StandardConstructors::plain_month_day;

2
core/engine/src/builtins/temporal/plain_time/mod.rs

@ -129,6 +129,8 @@ impl IntrinsicObject for PlainTime {
impl BuiltInConstructor for PlainTime { impl BuiltInConstructor for PlainTime {
const LENGTH: usize = 0; const LENGTH: usize = 0;
const P: usize = 15;
const SP: usize = 2;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::plain_time; StandardConstructors::plain_time;

2
core/engine/src/builtins/temporal/plain_year_month/mod.rs

@ -167,6 +167,8 @@ impl IntrinsicObject for PlainYearMonth {
impl BuiltInConstructor for PlainYearMonth { impl BuiltInConstructor for PlainYearMonth {
const LENGTH: usize = 2; const LENGTH: usize = 2;
const P: usize = 16;
const SP: usize = 1;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::plain_year_month; StandardConstructors::plain_year_month;

2
core/engine/src/builtins/temporal/zoned_date_time/mod.rs

@ -42,6 +42,8 @@ impl IntrinsicObject for ZonedDateTime {
impl BuiltInConstructor for ZonedDateTime { impl BuiltInConstructor for ZonedDateTime {
const LENGTH: usize = 2; const LENGTH: usize = 2;
const P: usize = 1;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::zoned_date_time; StandardConstructors::zoned_date_time;

2
core/engine/src/builtins/typed_array/builtin.rs

@ -165,6 +165,8 @@ impl BuiltInObject for BuiltinTypedArray {
impl BuiltInConstructor for BuiltinTypedArray { impl BuiltInConstructor for BuiltinTypedArray {
const LENGTH: usize = 0; const LENGTH: usize = 0;
const P: usize = 37;
const SP: usize = 3;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::typed_array; StandardConstructors::typed_array;

2
core/engine/src/builtins/typed_array/mod.rs

@ -94,6 +94,8 @@ impl<T: TypedArrayMarker> BuiltInObject for T {
impl<T: TypedArrayMarker> BuiltInConstructor for T { impl<T: TypedArrayMarker> BuiltInConstructor for T {
const LENGTH: usize = 3; const LENGTH: usize = 3;
const P: usize = 1;
const SP: usize = 2;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
<Self as TypedArrayMarker>::ERASED.standard_constructor(); <Self as TypedArrayMarker>::ERASED.standard_constructor();

2
core/engine/src/builtins/weak/weak_ref.rs

@ -53,6 +53,8 @@ impl BuiltInObject for WeakRef {
impl BuiltInConstructor for WeakRef { impl BuiltInConstructor for WeakRef {
/// The amount of arguments the `WeakRef` constructor takes. /// The amount of arguments the `WeakRef` constructor takes.
const LENGTH: usize = 1; const LENGTH: usize = 1;
const P: usize = 2;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::weak_ref; StandardConstructors::weak_ref;

2
core/engine/src/builtins/weak_map/mod.rs

@ -60,6 +60,8 @@ impl BuiltInObject for WeakMap {
impl BuiltInConstructor for WeakMap { impl BuiltInConstructor for WeakMap {
/// The amount of arguments the `WeakMap` constructor takes. /// The amount of arguments the `WeakMap` constructor takes.
const LENGTH: usize = 0; const LENGTH: usize = 0;
const P: usize = 5;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::weak_map; StandardConstructors::weak_map;

2
core/engine/src/builtins/weak_set/mod.rs

@ -58,6 +58,8 @@ impl BuiltInObject for WeakSet {
impl BuiltInConstructor for WeakSet { impl BuiltInConstructor for WeakSet {
/// The amount of arguments the `WeakSet` constructor takes. /// The amount of arguments the `WeakSet` constructor takes.
const LENGTH: usize = 0; const LENGTH: usize = 0;
const P: usize = 4;
const SP: usize = 0;
const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor = const STANDARD_CONSTRUCTOR: fn(&StandardConstructors) -> &StandardConstructor =
StandardConstructors::weak_set; StandardConstructors::weak_set;

3
core/engine/src/context/icu.rs

@ -1,5 +1,6 @@
use std::{cell::OnceCell, fmt::Debug}; use std::{cell::OnceCell, fmt::Debug};
use boa_profiler::Profiler;
use icu_casemap::CaseMapper; use icu_casemap::CaseMapper;
use icu_locid_transform::{LocaleCanonicalizer, LocaleExpander, LocaleTransformError}; use icu_locid_transform::{LocaleCanonicalizer, LocaleExpander, LocaleTransformError};
use icu_normalizer::{ComposingNormalizer, DecomposingNormalizer, NormalizerError}; use icu_normalizer::{ComposingNormalizer, DecomposingNormalizer, NormalizerError};
@ -89,6 +90,7 @@ impl IntlProvider {
pub(crate) fn try_new_with_buffer_provider( pub(crate) fn try_new_with_buffer_provider(
provider: (impl BufferProvider + 'static), provider: (impl BufferProvider + 'static),
) -> IntlProvider { ) -> IntlProvider {
let _timer = Profiler::global().start_event("ICU::try_new_with_buffer_provider", "ICU");
Self { Self {
locale_canonicalizer: OnceCell::new(), locale_canonicalizer: OnceCell::new(),
locale_expander: OnceCell::new(), locale_expander: OnceCell::new(),
@ -106,6 +108,7 @@ impl IntlProvider {
pub(crate) fn try_new_with_any_provider( pub(crate) fn try_new_with_any_provider(
provider: (impl AnyProvider + 'static), provider: (impl AnyProvider + 'static),
) -> IntlProvider { ) -> IntlProvider {
let _timer = Profiler::global().start_event("ICU::try_new_with_any_provider", "ICU");
Self { Self {
locale_canonicalizer: OnceCell::new(), locale_canonicalizer: OnceCell::new(),
locale_expander: OnceCell::new(), locale_expander: OnceCell::new(),

1
core/engine/src/context/mod.rs

@ -1052,6 +1052,7 @@ impl ContextBuilder {
// TODO: try to use a custom error here, since most of the `JsError` APIs // TODO: try to use a custom error here, since most of the `JsError` APIs
// require having a `Context` in the first place. // require having a `Context` in the first place.
pub fn build(self) -> JsResult<Context> { pub fn build(self) -> JsResult<Context> {
let _timer = Profiler::global().start_event("Ctx::build", "context");
if self.can_block { if self.can_block {
if CANNOT_BLOCK_COUNTER.get() > 0 { if CANNOT_BLOCK_COUNTER.get() > 0 {
return Err(JsNativeError::typ() return Err(JsNativeError::typ()

2
core/engine/src/module/loader.rs

@ -1,5 +1,6 @@
use std::path::{Component, Path, PathBuf}; use std::path::{Component, Path, PathBuf};
use boa_profiler::Profiler;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use boa_gc::GcRefCell; use boa_gc::GcRefCell;
@ -251,6 +252,7 @@ pub struct SimpleModuleLoader {
impl SimpleModuleLoader { impl SimpleModuleLoader {
/// Creates a new `SimpleModuleLoader` from a root module path. /// Creates a new `SimpleModuleLoader` from a root module path.
pub fn new<P: AsRef<Path>>(root: P) -> JsResult<Self> { pub fn new<P: AsRef<Path>>(root: P) -> JsResult<Self> {
let _timer = Profiler::global().start_event("Loader::new", "Loader");
if cfg!(target_family = "wasm") { if cfg!(target_family = "wasm") {
return Err(JsNativeError::typ() return Err(JsNativeError::typ()
.with_message("cannot resolve a relative path in WASM targets") .with_message("cannot resolve a relative path in WASM targets")

21
core/engine/src/object/shape/property_table.rs

@ -1,11 +1,9 @@
use std::{cell::RefCell, rc::Rc};
use rustc_hash::FxHashMap;
use crate::{ use crate::{
object::shape::slot::{Slot, SlotAttributes}, object::shape::slot::{Slot, SlotAttributes},
property::PropertyKey, property::PropertyKey,
}; };
use rustc_hash::{FxBuildHasher, FxHashMap};
use std::{cell::RefCell, rc::Rc};
/// The internal representation of [`PropertyTable`]. /// The internal representation of [`PropertyTable`].
#[derive(Default, Debug, Clone)] #[derive(Default, Debug, Clone)]
@ -15,6 +13,14 @@ pub(crate) struct PropertyTableInner {
} }
impl PropertyTableInner { impl PropertyTableInner {
/// Returns a new table with a given minimum capacity.
pub(crate) fn with_capacity(capacity: usize) -> Self {
Self {
map: FxHashMap::with_capacity_and_hasher(capacity, FxBuildHasher),
keys: Vec::with_capacity(capacity),
}
}
/// Returns all the keys, in insertion order. /// Returns all the keys, in insertion order.
pub(crate) fn keys(&self) -> Vec<PropertyKey> { pub(crate) fn keys(&self) -> Vec<PropertyKey> {
self.keys_cloned_n(self.keys.len() as u32) self.keys_cloned_n(self.keys.len() as u32)
@ -74,6 +80,13 @@ pub(crate) struct PropertyTable {
} }
impl PropertyTable { impl PropertyTable {
/// Creates a new `PropertyTable` with the specified capacity.
pub(crate) fn with_capacity(capacity: usize) -> Self {
Self {
inner: Rc::new(RefCell::new(PropertyTableInner::with_capacity(capacity))),
}
}
/// Returns the inner representation of a [`PropertyTable`]. /// Returns the inner representation of a [`PropertyTable`].
pub(super) fn inner(&self) -> &RefCell<PropertyTableInner> { pub(super) fn inner(&self) -> &RefCell<PropertyTableInner> {
&self.inner &self.inner

3
core/engine/src/object/shape/shared_shape/mod.rs

@ -186,7 +186,8 @@ impl SharedShape {
forward_transitions: ForwardTransition::default(), forward_transitions: ForwardTransition::default(),
prototype: None, prototype: None,
property_count: 0, property_count: 0,
property_table: PropertyTable::default(), // Most of the time the root shape initiates with between 1-4 properties.
property_table: PropertyTable::with_capacity(4),
previous: None, previous: None,
flags: ShapeFlags::default(), flags: ShapeFlags::default(),
transition_count: 0, transition_count: 0,

1
core/engine/src/vm/mod.rs

@ -110,6 +110,7 @@ unsafe impl Trace for ActiveRunnable {
impl Vm { impl Vm {
/// Creates a new virtual machine. /// Creates a new virtual machine.
pub(crate) fn new(realm: Realm) -> Self { pub(crate) fn new(realm: Realm) -> Self {
let _timer = Profiler::global().start_event("VM::new", "VM");
Self { Self {
frames: Vec::with_capacity(16), frames: Vec::with_capacity(16),
frame: CallFrame::new( frame: CallFrame::new(

Loading…
Cancel
Save