Skip to content

Optimize object literals #974

Open
Open
@bnoordhuis

Description

@bnoordhuis
function o(x,y,z){ return {x,y,z} }

Produces bytecode that sets the fields 1-by-1:

;; function o(x, y, z) { return {x, y, z} }

        object         
        get_arg0        0    ; x
        define_field    x
        get_arg1        1    ; y
        define_field    y
        get_arg2        2    ; z
        define_field    z
        return         

It should be more efficient to use an "object template" that describes what properties the object has:

;; function o(x, y, z) { return {x, y, z} }

        get_arg0        0    ; x
        get_arg1        1    ; y
        get_arg2        2    ; z
        define_object <id>   ; ( x y z -- o )
        return         

Benefits:

  • reduces bytecode size
  • object layout is known upfront, don't have to update JSShape repeatedly

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions