Skip to content
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

Optimize object literals #974

Open
bnoordhuis opened this issue Mar 13, 2025 · 0 comments
Open

Optimize object literals #974

bnoordhuis opened this issue Mar 13, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@bnoordhuis
Copy link
Contributor

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
@bnoordhuis bnoordhuis added the enhancement New feature or request label Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant