Skip to content

feat(v8/scripting): swap from msgpack-lite to msgpackr - #3201

Merged
prikolium-cfx merged 1 commit into
citizenfx:masterfrom
thelindat:feat/msgpackr
Mar 12, 2025
Merged

feat(v8/scripting): swap from msgpack-lite to msgpackr#3201
prikolium-cfx merged 1 commit into
citizenfx:masterfrom
thelindat:feat/msgpackr

Conversation

@thelindat

@thelindat thelindat commented Feb 27, 2025

Copy link
Copy Markdown
Contributor

Goal of this PR

Swaps out the outdated and unsupported msgpack-lite package for msgpackr, improving performance (58-95% faster depending on data and size) and adding support for more features (some are disabled for compatibility purposes).

How is this PR achieving the goal

Swaps out the custom version of msgpack-lite with msgpackr, adds bufferish to maintain backwards-compatibility for unknown types, and uses some patches to behave more like msgpack-lite.

This PR applies to the following area(s)

ScRT: JS

Successfully tested on

Game builds: FXServer 13019, FiveM 3258, RedM 1491

Platforms: Windows

Checklist

  • Code compiles and has been tested successfully.
  • Code explains itself well and/or is documented.
  • My commit message explains what the changes do and what they are for.
  • No extra compilation warnings are added by these changes.

Fixes issues

Supersedes #2931 and #3018.

@github-actions github-actions Bot added the triage Needs a preliminary assessment to determine the urgency and required action label Feb 27, 2025
@AvarianKnight

Copy link
Copy Markdown
Contributor

Might be worth only disabling moreTypes for sessionmanager-rdr3, and adding a metadata the resource can define to turn off moreTypes and check if its set with https://docs.fivem.net/natives/?_0x964BAB1D

@thelindat

Copy link
Copy Markdown
Contributor Author

Perhaps in a separate PR which can enable moreTypes and also add some extensions that are "breaking" (e.g. vectors to array or a builtin vector class) - rather than moving the goalpost here?

@thelindat
thelindat marked this pull request as ready for review February 27, 2025 16:40
@github-actions github-actions Bot added ScRT: JS Issues/PRs related to the JavaScript scripting runtime invalid Requires changes before it's considered valid and can be (re)triaged and removed triage Needs a preliminary assessment to determine the urgency and required action labels Feb 27, 2025

@nihonium-cfx nihonium-cfx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few things to improve:

  1. Add licenses, links to original and authors mentions to the files containing third-party code (as it was with msgpack-lite).
  2. Document any changes made to the third-party code so that when such code would need to get changes from the upstream - we'd know what changes to re-apply.

Nits:

  • main.js is not the most well "styled" code for sure, but it'd be great not to worsen it and keep using trailing semicolons and commas along with proper indentation for our code (third-party excluded, of course).

Comment thread data/shared/citizen/scripting/v8/main.js Outdated
Comment thread data/shared/citizen/scripting/v8/main.js Outdated
@nihonium-cfx nihonium-cfx added enhancement Feature or other request that adds functionality or improved usability and removed invalid Requires changes before it's considered valid and can be (re)triaged labels Feb 28, 2025
@github-actions github-actions Bot added the invalid Requires changes before it's considered valid and can be (re)triaged label Feb 28, 2025
@thelindat

Copy link
Copy Markdown
Contributor Author

Licenses and links added to the built files, including a link to my fork of msgpackr so you can see the commit. I made sure to comment out the original code and include a note about msgpack-lite above the modified code; but it's fairly minimal. Some parts might not even be strictly necessary - but better safe than sorry.

I'm using the msgpackr global that's already exposed by the library, which is now removed to prevent any funny business.
msgpack_packr is removed since it doesn't serve much purpose, and I've exposed addExtension as msgpack_extend for clarity and consistency.

@nihonium-cfx nihonium-cfx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff!

Comment thread data/shared/citizen/scripting/v8/msgpack.d.ts
@AvarianKnight

AvarianKnight commented Feb 28, 2025

Copy link
Copy Markdown
Contributor

The original reason packr was exposed was because msgpackr supports structures, see this section, and you can add them via the packr object (iirc)

Co-authored-by: Dillon Skaggs <dillon@dillonskaggs.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Feature or other request that adds functionality or improved usability invalid Requires changes before it's considered valid and can be (re)triaged ready-to-merge This PR is enqueued for merging ScRT: JS Issues/PRs related to the JavaScript scripting runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants