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

Encoding performance improvements #152

Merged
merged 12 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions rome.json → biome.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
{
"$schema": "./node_modules/rome/configuration_schema.json",
"files": {
"ignore": ["dist","ref","pages"]
"ignore": ["dist", "ref", "pages", ".vscode"]
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"performance": { "noDelete": "off" }
"performance": {
"noDelete": "off"
},
"complexity": {
"noForEach": "off"
},
"a11y": {
"all": false
},
"style": {
"noParameterAssign": "off"
}
}
},
"formatter": {
Expand All @@ -18,4 +29,4 @@
"quoteStyle": "single"
}
}
}
}
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"url": "git+https://github.com/aravindet/graffy.git"
},
"scripts": {
"format": "rome check --apply-suggested . && rome format --write .",
"lint": "rome ci .",
"format": "biome check --apply .",
"lint": "biome ci .",
"package": "./scripts/package.js",
"start": "node src/example/server.js",
"test": "NODE_OPTIONS=--experimental-vm-modules NODE_ENV=testing jest",
Expand All @@ -28,7 +28,9 @@
"homepage": "https://graffy.org",
"devDependencies": {
"@babel/preset-react": "^7.16.7",
"@biomejs/biome": "^1.5.3",
"@faker-js/faker": "^7.6.0",
"@testing-library/react": "^13.4.0",
"@types/debug": "^4.1.7",
"@types/jest": "^29.2.4",
"@types/pg": "^8.6.5",
Expand All @@ -49,7 +51,6 @@
"react-dom": "^18.2.0",
"react-test-renderer": "^18.2.0",
"rimraf": "^3.0.2",
"rome": "^11.0.0",
"sql-template-tag": "^5.0.3",
"typescript": "^4.9.4",
"uuid": "^9.0.0",
Expand All @@ -60,8 +61,5 @@
"peerDependencies": {
"pg": "^8.0.0",
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@testing-library/react": "^13.4.0"
}
}
13 changes: 6 additions & 7 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { mkdir, readFile, writeFile } from 'fs/promises';
import { builtinModules } from 'module';
import { src, dst, ownPattern, read } from './utils.js';
import { depVersions, peerDepVersions, use } from './deps.js';
import { mkdir, readFile, writeFile } from 'fs/promises';
import { build as viteBuild } from 'vite';
import { depVersions, peerDepVersions, use } from './deps.js';
import { dst, ownPattern, read, src } from './utils.js';

const depPattern = /^[^@][^/]*|^@[^/]*\/[^/]*/;

Expand Down Expand Up @@ -92,11 +92,10 @@ export default async function build(name, version, watch, onUpdate) {

console.log(`INFO [${name}] built, watching for changes...`);
return true;
} else {
writePackageJson(imports);
console.log(`INFO [${name}] built`);
return true;
}
writePackageJson(imports);
console.log(`INFO [${name}] built`);
return true;

async function writePackageJson(imports) {
let dependencies;
Expand Down
2 changes: 1 addition & 1 deletion scripts/interlink.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { yarn, ownPattern, read } from './utils.js';
import { ownPattern, read, yarn } from './utils.js';

export default async function link(name) {
try {
Expand Down
4 changes: 0 additions & 4 deletions scripts/jestDomEnvironment.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
const BaseEnvironment = require('jest-environment-jsdom').TestEnvironment;

class DomEnvironment extends BaseEnvironment {
constructor(config, context) {
super(config, context);
}

async setup() {
await super.setup();
this.global.TextDecoder = TextDecoder;
Expand Down
14 changes: 7 additions & 7 deletions scripts/package.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/usr/bin/env node

import { mkdir, readdir } from 'fs/promises';
import os from 'os';
import { mkdir, readdir } from 'fs/promises';
import pMap from 'p-map';
import mRimraf from 'rimraf';
import yargs from 'yargs';
import pMap from 'p-map';

import version from './version.js';
import build from './build.js';
import publish from './publish.js';
import link from './link.js';
import interlink from './interlink.js';
import link from './link.js';
import publish from './publish.js';
import tag from './tag.js';
import types, { terminateWorkers } from './types.js';
import { src, dst } from './utils.js';
import { dst, src } from './utils.js';
import version from './version.js';

const { sync: rimraf } = mRimraf;

Expand All @@ -34,7 +34,7 @@ function onUpdate(name, fileName) {
if (!argv.notypes) types(name, fileName);
}

(async function () {
(async () => {
const ver = await version(argv._[0]);
console.log(`INFO packaging version ${ver}`);

Expand Down
6 changes: 3 additions & 3 deletions scripts/tscworker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parentPort } from 'worker_threads';
import ts from 'typescript';
import { src, dst } from './utils.js';
import { dirname } from 'path';
import ts from 'typescript';
import { parentPort } from 'worker_threads';
import { dst, src } from './utils.js';

parentPort.on('message', (message) => {
const { name, fileName } = message;
Expand Down
2 changes: 1 addition & 1 deletion scripts/types.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { root } from './utils.js';
import { Worker } from 'worker_threads';
import { root } from './utils.js';

const workerPool = [];

Expand Down
4 changes: 2 additions & 2 deletions scripts/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { execFile as cExecFile } from 'child_process';
import { readFileSync } from 'fs';
import { join } from 'path';
import { fileURLToPath } from 'url';
import { execFile as cExecFile } from 'child_process';
import { promisify } from 'util';
import { readFileSync } from 'fs';

const execFile = promisify(cExecFile);

Expand Down
2 changes: 1 addition & 1 deletion scripts/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default async function version(str) {
.reduce((latest, vstring) => {
const version = vstring
.split(/[.-]/)
.map((seg) => (isNaN(seg) ? seg : parseInt(seg)));
.map((seg) => (Number.isNaN(seg) ? seg : parseInt(seg)));

for (let i = 0; i < 5; i++) {
const atPre = i === 3;
Expand Down
2 changes: 1 addition & 1 deletion src/cache/cache.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { jest } from '@jest/globals';
import Graffy from '@graffy/core';
import { jest } from '@jest/globals';
import Cache from './index.js';

describe('cache', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/cache/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {
getKnown,
makeWatcher,
merge,
slice,
mergeStreams,
makeWatcher,
getKnown,
slice,
} from '@graffy/common';
import { mapStream } from '@graffy/stream';
// import { debug } from '@graffy/testing';
Expand Down
2 changes: 1 addition & 1 deletion src/client/Socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default function Socket(
function maybeConnect() {
const connDelay =
lastAttempt +
Math.min(MAX_DELAY, MIN_DELAY * Math.pow(DELAY_GROWTH, attempts)) -
Math.min(MAX_DELAY, MIN_DELAY * DELAY_GROWTH ** attempts) -
Date.now();

log('Will reconnect in', connDelay, 'ms');
Expand Down
6 changes: 3 additions & 3 deletions src/client/client.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { jest } from '@jest/globals';
import Graffy from '@graffy/core';
import { pack, unpack } from '@graffy/common';
import Graffy from '@graffy/core';
import { e } from '@graffy/testing/encoder.js';
import { jest } from '@jest/globals';

jest.unstable_mockModule('./Socket', () => ({
default: jest.fn(() => ({
Expand All @@ -16,7 +16,7 @@ const MockSocket = (await import('./Socket.js')).default;

describe('wsClient', () => {
// @ts-ignore
globalThis.WebSocket = function () {};
globalThis.WebSocket = () => {};

let store;

Expand Down
2 changes: 1 addition & 1 deletion src/client/httpClient.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pack, unpack, add } from '@graffy/common';
import { add, pack, unpack } from '@graffy/common';
import { makeStream } from '@graffy/stream';

function getOptionsParam(options) {
Expand Down
3 changes: 1 addition & 2 deletions src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const WSRE = /^wss?:\/\//;
export default function GraffyClient(baseUrl, options) {
if (WSRE.test(baseUrl)) {
return wsClient(baseUrl, options);
} else {
return httpClient(baseUrl, options);
}
return httpClient(baseUrl, options);
}
2 changes: 1 addition & 1 deletion src/client/wsClient.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { makeStream } from '@graffy/stream';
import { makeWatcher, pack, unpack } from '@graffy/common';
import { makeStream } from '@graffy/stream';
import Socket from './Socket.js';

const wsClient =
Expand Down
12 changes: 6 additions & 6 deletions src/common/coding/args.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { encode as encodeValue, decode as decodeValue } from './struct.js';
import { keyStep, keyAfter, keyBefore } from '../ops/step.js';
import { keyAfter, keyBefore, keyStep } from '../ops/step.js';
import {
MIN_KEY,
MAX_KEY,
MIN_KEY,
cmp,
errIf,
isEmpty,
isPlainObject,
isDef,
isEmpty,
isMaxKey,
isMinKey,
cmp,
isPlainObject,
} from '../util.js';
import { decode as decodeValue, encode as encodeValue } from './struct.js';

function decodeBound(bound) {
const { key, step } = keyStep(bound);
Expand Down
8 changes: 4 additions & 4 deletions src/common/coding/decodeTree.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isBranch, isLink, isPrefix, isRange } from '../node/index.js';
import { keyAfter } from '../ops/index.js';
import { clone, cmp, isDef, isEmpty, isMaxKey, isMinKey } from '../util.js';
import { decode as decodeArgs, splitArgs } from './args.js';
import { decode as decodePath } from './path.js';
import { isEmpty, isDef, isMinKey, isMaxKey, cmp, clone } from '../util.js';
import { keyAfter } from '../ops/index.js';
import { isRange, isBranch, isPrefix, isLink } from '../node/index.js';

const PRE_CHI_PUT = Symbol('PREFIX_CHILDREN_$PUT');

Expand Down Expand Up @@ -93,7 +93,7 @@ function decode(nodes = [], { isGraph } = {}) {
$val = clone($val);
Object.defineProperty($val, '$val', { value: true });
}
// rome-ignore format: tertnary chain
// biome-ignore format: tertnary chain
collection[$key] = (
isDef($val) ? $val :
!isEmpty(item) || item.$ref || item.$put ? item :
Expand Down
38 changes: 19 additions & 19 deletions src/common/coding/decorate.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { decodeGraph } from './decodeTree.js';
import {
encode as encodePath,
decode as decodePath,
splitRef,
} from './path.js';
import {
splitArgs,
encode as encodeArgs,
decode as decodeArgs,
} from './args.js';
import { unwrap, getNodeValue, IS_VAL } from '../ops/index.js';
import { findFirst, isRange } from '../node/index.js';
import { IS_VAL, getNodeValue, unwrap } from '../ops/index.js';
import {
MIN_KEY,
cmp,
isDef,
isPlainObject,
isEmpty,
isMinKey,
cmp,
MIN_KEY,
isPlainObject,
} from '../util.js';
import { isRange, findFirst } from '../node/index.js';
import {
decode as decodeArgs,
encode as encodeArgs,
splitArgs,
} from './args.js';
import { decodeGraph } from './decodeTree.js';
import {
decode as decodePath,
encode as encodePath,
splitRef,
} from './path.js';

const REF = Symbol();
const PRE = Symbol();
Expand Down Expand Up @@ -204,14 +204,14 @@ function addPageMeta(graph, args) {
}
}

// rome-ignore format: ternary chain
// biome-ignore format: ternary chain
const $prev =
isDef($page.$after) ? { ...filter, $last: count, $until: $page.$after } :
isDef($page.$since) ? { ...filter, $last: count, $before: $page.$since } :
null;

// rome-ignore format: ternary chain
let $next =
// biome-ignore format: ternary chain
const $next =
isDef($page.$before) ? { ...filter, $first: count, $since: $page.$before } :
isDef($page.$until) ? { ...filter, $first: count, $after: $page.$until } :
null;
Expand Down
Loading
Loading