GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Reuse Encoder/Decoder instance? · Issue #172 · msgpack/msgpack-javascript

Reuse Encoder/Decoder instance? #172

New issue
Copy link
New issue
Copy link
Open
Open
Reuse Encoder/Decoder instance?#172
Copy link

Description

@buu700
buu700
opened on Apr 29, 2021
Issue body actions

The readme says that encoding is 20% faster when reusing an Encoder instance. If that's the case, is there any reason not to just memoize them in encode (or at least reuse a default instance when no options are set)?

Activity

  1. gfx
    added
    Docs
    on Apr 30, 2021
  2. gfx commented on Apr 30, 2021

    @gfx
    gfx
    on Apr 30, 2021
    Member
    More actions

    That's a good question. There's an example in test/reuse-instances.test.ts, but they only accepts positional parameters right now, so I might change their interfaces to accept named parameters just like as encode({...}) and decode({...}).

  3. buu700 commented on Apr 30, 2021

    @buu700
    buu700
    on Apr 30, 2021
    Author
    More actions

    Oh, just to clarify, I wasn't asking about the documentation. I was suggesting an optimization to the default encode and decode functions / wondering whether there was a non-obvious reason that that hadn't been done.

  4. gfx commented on Apr 30, 2021

    @gfx
    gfx
    on Apr 30, 2021
    Member
    More actions

    Ah, sorry! Misunderstood.

    There're some reasons that we cannot memorize them:

    • instance.*Async() are not async-await safe (or not thread-safe)
    • the instance has lots of configuration parameters so it's difficult to memoize
  5. buu700 commented on Apr 30, 2021

    @buu700
    buu700
    on Apr 30, 2021
    Author
    More actions

    Got it, that makes sense. If memoizing isn't an option, what about just pre-initializing a default instance that gets used when options is undefined? That would at least cover the most common case (I'm assuming).

  6. gfx
    removed
    Docs
    on Apr 30, 2021
  7. gfx commented on Apr 30, 2021

    @gfx
    gfx
    on Apr 30, 2021
    Member
    More actions

    Sounds good. Will try it.

  8. buu700 commented on Apr 30, 2021

    @buu700
    buu700
    on Apr 30, 2021
    Author
    More actions

    Nice, thanks! I'd be happy to submit a PR if that would be helpful.

  9. buu700
    added 4 commits that reference this issue on May 4, 2021

    encode minor performance optimization

    44db5ec

    encode/decode minor performance optimization

    d338d94

    encode/decode minor performance optimization

    381f7e0

    encode/decode minor performance optimization

    252ea39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.