ForgeDoc Reconciliation Count Detector

Benchmark created on


Setup

const data = {"type":"Root","children":[{"type":"Text","children":[{"type":"String","children":[],"props":{"text":"Hello world from the Server!"},"key":"f87460b1-7e4f-4763-9049-b2d1522dc57a"}],"props":{},"key":"aedd7355-84b2-4e10-8eda-0f2e0b527546"},{"type":"Text","children":[{"type":"String","children":[],"props":{"text":"Loading..."},"key":"7b96baa5-7235-441b-8dae-9cc515203627"}],"props":{},"key":"24e0a51a-a3e3-4123-9f7f-89836e8f6953"},{"type":"Button","children":[{"type":"String","children":[],"props":{"text":"test"},"key":"55ea4532-58b4-45cb-b5db-aec59fa253cc"}],"props":{},"key":"c134efaf-f995-434b-818f-4dd381d8cc91"},{"type":"Button","children":[{"type":"String","children":[],"props":{"text":"a new button"},"key":"d48c1d1f-ff76-4998-a46d-d1ec5b6729e2"}],"props":{"appearance":"primary"},"key":"cf5d0171-245a-47eb-bffd-b2269849be8d"},{"type":"Form","children":[{"type":"Text","children":[{"type":"String","children":[],"props":{"text":"My form!"},"key":"2752168d-a016-4044-b2a8-f3aca7948a04"}],"props":{},"key":"b9d1561b-b28d-4dd2-bb71-57a08f5c6357"}],"props":{"submitButtonAppearance":"danger"},"key":"caaaa25c-4429-41d5-a480-25767011532d"}],"props":{},"key":"69a8ffb4-8f53-4718-891b-718bff175e9b"};

Test runner

Ready to run.

Testing in
TestOps/sec
JSON.Stringify - Find updated node (5 nodes)
function jsonStringifyTraverse (
  node,
  reconciliationCount,
) {
  let updated = false;
  try {
    JSON.stringify(node, (_, nestedValue) => {
      if (
        nestedValue !== undefined &&
        nestedValue['reconciliationCount'] === reconciliationCount
      ) {
        updated = true;
        throw new Error();
      }
      return nestedValue;
    });
  } catch (e) {
    // Ignore error, just quick exit
  }
  return updated;
};

jsonStringifyTraverse(data);
ready
Traverse recursive function - Find updated node (5 nodes)
const recursiveTraverse = (
  node,
  reconciliationCount,
) => {
  function traverse(obj) {
    if (obj.props && obj.props['reconciliationCount'] === reconciliationCount) {
      return true;
    }

    if (obj.children) {
      for (const child of obj.children) {
        if (traverse(child)) {
          return true;
        }
      }
    }

    return false;
  }

  return traverse(node);
};

recursiveTraverse(data);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.