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

chore(scripts): add compression routines for endpoints rulesets #4300

Merged
merged 4 commits into from Dec 20, 2022

Conversation

kuhe
Copy link
Contributor

@kuhe kuhe commented Dec 20, 2022

Issue

#4299

Description

Adds a script that compresses each service's ruleset object with one of two algorithms:

  • attempts to use the pattern detection recursive algorithm
  • if that fails, it uses the whitespace removal algorithm

This PR does not integrate this script into the client generation process.

main branch

du -sh clients/client-s3/src/endpoint/ruleset.ts
804K	clients/client-s3/src/endpoint/ruleset.ts

npm notice name:          @aws-sdk/client-s3
npm notice version:       3.234.0
npm notice filename:      @aws-sdk/client-s3-3.234.0.tgz
npm notice package size:  355.8 kB
npm notice unpacked size: 6.2 MB (yarn build && npm pack without downlevel types)

PR branch

du -sh clients/client-s3/src/endpoint/ruleset.ts
28K	clients/client-s3/src/endpoint/ruleset.ts

npm notice name:          @aws-sdk/client-s3
npm notice version:       3.234.0
npm notice filename:      @aws-sdk/client-s3-3.234.0.tgz
npm notice package size:  320.5 kB
npm notice unpacked size: 3.8 MB (yarn build && npm pack without downlevel types)

Testing

each algorithm runs self-verification using the input it is given before it is accepted. Because the whitespace removal algorithm is more or less immune to failure, it is the fallback.

Secondly, to show the two formats have no performance impact, the following performance test loads

  • A) the compressed JS format with patterns represented by variable references
  • B) the standard uncompressed JSON format

and then walks the entire object and inspects each value.

const marks = {
  js: [],
  json: [],
};

performanceTest();

function performanceTest() {
  {
    for (let i = 0; i < 10000; ++i) {
      const start = performance.now();
      loadJs();
      const end = performance.now();
      marks.js.push(end - start);
    }
  }

  {
    for (let i = 0; i < 10000; ++i) {
      const start = performance.now();
      loadJson();
      const end = performance.now();
      marks.json.push(end - start);
    }
  }

  console.log("js", marks.js.reduce((a, b) => a + b, 0) / marks.js.length);
  console.log("json", marks.json.reduce((a, b) => a + b, 0) / marks.json.length);
}

function loadJs() {
  const data = require("./s3");
  walkObject(data);
}

function loadJson() {
  const data = require("./s3.json");
  walkObject(data);
}

function walkObject(data) {
  switch (typeof data) {
    case "object":
      if (Array.isArray(data)) {
        data.forEach(walkObject);
        break;
      }
      Object.values(data).forEach(walkObject);
      break;
    default:
      if (data === -13534135) {
        throw new Error("comparison failed");
      }
  }
}

output:

js 0.5221970861673355
json 0.5317003727197647

@kuhe
Copy link
Contributor Author

kuhe commented Dec 20, 2022

For codegen changes, see #4301

@trivikr trivikr self-requested a review December 20, 2022 16:42
scripts/endpoints-ruleset/compress.js Outdated Show resolved Hide resolved
scripts/endpoints-ruleset/compress.js Outdated Show resolved Hide resolved
scripts/endpoints-ruleset/compress.js Outdated Show resolved Hide resolved
kuhe and others added 3 commits December 20, 2022 11:58
Co-authored-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
Co-authored-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
Co-authored-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
@kuhe kuhe merged commit 15c3976 into aws:main Dec 20, 2022
@kuhe kuhe deleted the chore/ruleset branch December 20, 2022 17:06
@github-actions
Copy link

github-actions bot commented Jan 4, 2023

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants