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

ENH: AMF3 over-the-wire optimization #1517

Open
EmosewaMC opened this issue Mar 27, 2024 · 0 comments
Open

ENH: AMF3 over-the-wire optimization #1517

EmosewaMC opened this issue Mar 27, 2024 · 0 comments
Labels
enhancement New feature or request P-Fixer This issue is confirmed, but is not prioritized to be fixed.

Comments

@EmosewaMC
Copy link
Collaborator

Is your feature request related to a problem?

Currently, the AMF3 serialization always writes the strings by value. This can be costly with an over the wire transfer with lots of data.

Describe the solution you'd like

An optimization would be, like the Deserializer, a serializer class which keeps track of what strings have been written and utilizes the reference part of the format. The following is a method of accomplishing this which will work:

class Writer {
  map<string, int> referenceTracker;
  void Serialize(string str, RakNet::BitStream* stream) {
    if (str.empty()) {
      stream->Write29bitInt(1); // empty strings are never passed by referenece
      return;
    }
    auto itr = referenceTracker.find(str);
    if (itr != referenceTracker.end()) {
      stream->Write29bitInt((itr->second << 1UL)); // shift left 1 and mark lowest bit with 0 to denote this is a reference to the previous string of number x.
      return;
    }
    auto size = referenceTracker.size(); // size pre-insert is the reference number
    referenceTracker[str] = size; // assign the number to this string value
    stream->Write29bitint((str.size() << 1) | 1); // bit 1 is the flag bit for a string size
    stream->Write(str.c_str(), str.size()); // write the string to the stream 
  }
}

the above code is simply an example and not representative of what a final product should look like and is mostly to get the idea across.

Repository breaking implications

Could break UI msgs

Describe alternatives you've considered

becoming one with AMF

Additional context

No response

@EmosewaMC EmosewaMC added enhancement New feature or request P-Fixer This issue is confirmed, but is not prioritized to be fixed. labels Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P-Fixer This issue is confirmed, but is not prioritized to be fixed.
Projects
None yet
Development

No branches or pull requests

1 participant