Skip to content

Instantly share code, notes, and snippets.

@pengx17
Last active April 11, 2023 01:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pengx17/9b838a0d4afb3b7ac1fb11dd83cf7c01 to your computer and use it in GitHub Desktop.
Save pengx17/9b838a0d4afb3b7ac1fb11dd83cf7c01 to your computer and use it in GitHub Desktop.
get blocksuite size footsprints
(async () => {
const { getBlocksuiteReader } = await import(
"https://unpkg.com/blocksuite-reader@0.0.6/dist/index.js"
);
const workspace = window.currentBlockSuiteWorkspace;
const workspaceId = workspace.room;
const reader = getBlocksuiteReader({
workspaceId: workspaceId,
Y: workspace.constructor.Y,
});
const pages = reader.docToPages(workspace.doc, true);
const allMd = pages.map((p) => "# " + p.title + "\n" + p.md).join("\n\n\n");
const pageNames = pages.map(p => p.title);
const mdSize = new TextEncoder().encode(allMd).length;
const binary = workspace.constructor.Y.encodeStateAsUpdate(workspace.doc);
const binSize = binary.length;
console.log('Pages in the workspace: ', pageNames);
console.table({
"Markdown size": mdSize,
"Binary size": binSize,
"Binary size / Markdown size": ((binSize / mdSize) * 100).toFixed(1) + "%",
});
})();
@pengx17
Copy link
Author

pengx17 commented Mar 1, 2023

Run the script in https://app.affine.pro

image

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