Skip to content

Commit

Permalink
json2pbf
Browse files Browse the repository at this point in the history
  • Loading branch information
itanka9 committed Nov 6, 2024
1 parent 76d7ad1 commit 00f9764
Show file tree
Hide file tree
Showing 10 changed files with 1,440 additions and 285 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Simple workflow for deploying static content to GitHub Pages
name: Deploy static content to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ['main']

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets the GITHUB_TOKEN permissions to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment
concurrency:
group: 'pages'
cancel-in-progress: true

jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 18
cache: 'npm'
- name: Install dependencies
run: npm install
- name: Build
run: npm run build -- --base=/json2pbf/
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
path: './dist'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<title>Wroker test</title>
</head>
<body>
<script src="./index.ts"></script>
<script type="module" src="./index.ts"></script>
</body>
</html>
66 changes: 57 additions & 9 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
import { unpackJson } from './src/json2pbf';
import { unpack } from './src/json2pbf';
import { ITERATIONS_COUNT, JSON_TEMPLATE } from './src/config';
import { unpackBfsm } from './src/bfsm';

const worker = new Worker(new URL('./src/worker.ts', import.meta.url));
const worker = new Worker(new URL('./src/worker.ts', import.meta.url), {
type: 'module',
});
const decoder = new TextDecoder('utf-8');

function unpackAndBuildMap(data: ArrayBuffer, columnar = false) {
const unpacked = unpack(data);
const map = new Map();
if (columnar) {
for (let i = 0; i < unpacked.id.length; i++) {
const featureState = {
hidden: unpacked.hidden[i]
}
map.set(unpacked.id[i], featureState);

}
} else {
for (let i = 0; i < unpacked.length; i++) {
const item = unpacked[i];
const featureState = {
hidden: item.hidden
}
map.set(item.id, featureState);
}
}
return map;
}

async function makeTests() {
function waitResults(type: number, unpack: (data: any) => { data: any; hash: string }) {
function waitResults(type: number, unpack: (data: any) => { data: any; }) {
const results: any[] = [];
const converted: any[] = [];
return new Promise<void>((res) => {
Expand Down Expand Up @@ -34,28 +61,49 @@ async function makeTests() {
console.log('Массив ', JSON_TEMPLATE);
console.log(`Передаем из воркера в главный поток ${ITERATIONS_COUNT} раз`);
console.group('передаем типизированный массив напрямую');
await waitResults(0, (data) => ({ data, hash: data.toString() }));
await waitResults(0, (data) => ({ data }));
console.groupEnd();

console.group('передаем объект напрямую');
await waitResults(1, (data) => ({ data, hash: JSON.stringify(data) }));
await waitResults(1, (data) => ({ data }));
console.groupEnd();

console.group('передаем как строку');
await waitResults(2, (data) => ({ data: JSON.parse(data), hash: data }));
await waitResults(2, (data) => ({ data: JSON.parse(data) }));
console.groupEnd();

console.group('JSON.parse + TextDecoder');
await waitResults(3, (data) => {
const hash = decoder.decode(data);
return { data: JSON.parse(hash), hash };
return { data: JSON.parse(hash) };
});
console.groupEnd();

console.group('PBF');
await waitResults(4, (data) => {
const unpacked = unpackJson(data);
return { data: unpacked, hash: JSON.stringify(unpacked) };
const unpacked = unpackAndBuildMap(data);
return { data: unpacked };
});
console.groupEnd();

console.group('PBF (row)');
await waitResults(5, (data) => {
const unpacked = unpackAndBuildMap(data);
return { data: unpacked };
});
console.groupEnd();

console.group('PBF (columnar)');
await waitResults(6, (data) => {
const unpacked = unpackAndBuildMap(data, true);
return { data: unpacked };
});
console.groupEnd();

console.group('BFSM');
await waitResults(7, (data) => {
const unpacked = unpackBfsm(data);
return { data: unpacked };
});
console.groupEnd();
}
Expand Down
Loading

0 comments on commit 00f9764

Please sign in to comment.