Skip to content

Commit 55fd23f

Browse files
committed
feat: removed HPS because we can now use --expose_externalize_string to detect the encoding of a string. Additionally, we have submitted a PR to Node.js for detecting string encoding. If this PR is merged, we will be able to achieve good performance without this flag.
1 parent ec6ff4a commit 55fd23f

22 files changed

+25
-1358
lines changed

LICENSE

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,6 @@ The text of each license is also included in licenses/LICENSE-[project].txt.
272272
java/fury-core/src/main/java/org/apache/fury/type/Generics.java
273273
java/fury-core/src/test/java/org/apache/fury/type/GenericsTest.java
274274

275-
* v8 (https://chromium.googlesource.com/v8/v8.git)
276-
Files:
277-
javascript/packages/hps/src/v8-fast-api-calls.h
278-
279-
280275
================================================================
281276
MIT licenses
282277
================================================================

ci/release.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,6 @@ def bump_version(**kwargs):
148148
new_version,
149149
_update_js_version,
150150
)
151-
_bump_version(
152-
"javascript/packages/hps",
153-
"package.json",
154-
new_version,
155-
_update_js_version,
156-
)
157151
else:
158152
raise NotImplementedError(f"Unsupported {lang}")
159153

docs/guide/xlang_serialization_guide.md

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,7 @@ func main() {
9898
```javascript
9999
import Fury from '@furyjs/fury';
100100

101-
/**
102-
* @furyjs/hps use v8's fast-calls-api that can be called directly by jit, ensure that the version of Node is 20 or above.
103-
* Experimental feature, installation success cannot be guaranteed at this moment
104-
* If you are unable to install the module, replace it with `const hps = null;`
105-
**/
106-
import hps from '@furyjs/hps';
107-
108-
const fury = new Fury({ hps });
101+
const fury = new Fury({});
109102
const input = fury.serialize('hello fury');
110103
const result = fury.deserialize(input);
111104
console.log(result);
@@ -317,18 +310,11 @@ func main() {
317310
```javascript
318311
import Fury, { Type, InternalSerializerType } from '@furyjs/fury';
319312

320-
/**
321-
* @furyjs/hps use v8's fast-calls-api that can be called directly by jit, ensure that the version of Node is 20 or above.
322-
* Experimental feature, installation success cannot be guaranteed at this moment
323-
* If you are unable to install the module, replace it with `const hps = null;`
324-
**/
325-
import hps from '@furyjs/hps';
326-
327313
// Now we describe data structures using JSON, but in the future, we will use more ways.
328314
const description = Type.object('example.foo', {
329315
foo: Type.string(),
330316
});
331-
const fury = new Fury({ hps });
317+
const fury = new Fury({});
332318
const { serialize, deserialize } = fury.registerSerializer(description);
333319
const input = serialize({ foo: 'hello fury' });
334320
const result = deserialize(input);
@@ -490,19 +476,13 @@ func main() {
490476

491477
```javascript
492478
import Fury, { Type } from '@furyjs/fury';
493-
/**
494-
* @furyjs/hps use v8's fast-calls-api that can be called directly by jit, ensure that the version of Node is 20 or above.
495-
* Experimental feature, installation success cannot be guaranteed at this moment
496-
* If you are unable to install the module, replace it with `const hps = null;`
497-
**/
498-
import hps from '@furyjs/hps';
499479

500480
const description = Type.object('example.foo', {
501481
foo: Type.string(),
502482
bar: Type.object('example.foo'),
503483
});
504484

505-
const fury = new Fury({ hps });
485+
const fury = new Fury({});
506486
const { serialize, deserialize } = fury.registerSerializer(description);
507487
const data: any = {
508488
foo: 'hello fury',

javascript/README.md

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,18 @@ The Cross-Language part of the protocol is not stable, so the output of this lib
88

99
```shell
1010
npm install @furyjs/fury
11-
npm install @furyjs/hps
1211
```
1312

1413
## Usage
1514

1615
```Javascript
1716
import Fury, { Type, InternalSerializerType } from '@furyjs/fury';
1817

19-
/**
20-
* @furyjs/hps use v8's fast-calls-api that can be called directly by jit, ensure that the version of Node is 20 or above.
21-
* Experimental feature, installation success cannot be guaranteed at this moment
22-
* If you are unable to install the module, replace it with `const hps = null;`
23-
**/
24-
import hps from '@furyjs/hps';
25-
2618
// Now we describe data structures using JSON, but in the future, we will use more ways.
2719
const description = Type.object('example.foo', {
2820
foo: Type.string(),
2921
});
30-
const fury = new Fury({ hps });
22+
const fury = new Fury({});
3123
const { serialize, deserialize } = fury.registerSerializer(description);
3224
const input = serialize({ foo: 'hello fury' });
3325
const result = deserialize(input);
@@ -39,11 +31,3 @@ console.log(result);
3931
### fury
4032

4133
Fury protocol implementation. It generates JavaScript code at runtime to make sure that all the code could be optimized by v8 JIT efficiently.
42-
43-
### hps
44-
45-
Node.js high-performance suite, ensuring that your Node.js version is 20 or later.
46-
47-
`hps` is use for detect the string type in v8. Fury support latin1 and utf8 string both, we should get the certain type of string before write it
48-
in buffer. It is slow to detect the string is latin1 or utf8, but hps can detect it by a hack way, which is called FASTCALL in v8.
49-
so it is not stable now.

javascript/benchmark/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919

2020
const Fury = require("@furyjs/fury");
2121
const utils = require("@furyjs/fury/dist/lib/util");
22-
const hps = require('@furyjs/hps');
23-
const fury = new Fury.default({ hps, refTracking: false, useSliceString: true });
22+
const fury = new Fury.default({ refTracking: false, useSliceString: true });
2423
const Benchmark = require("benchmark");
2524
const protobuf = require("protobufjs");
2625
const path = require('path');

javascript/benchmark/map.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@
1919

2020
const Fury = require("@furyjs/fury");
2121
const beautify = require("js-beautify");
22-
const hps = require('@furyjs/hps');
2322
const fury = new Fury.default({
24-
hps, refTracking: false, useSliceString: true, hooks: {
23+
refTracking: false, useSliceString: true, hooks: {
2524
afterCodeGenerated: (code) => {
2625
return beautify.js(code, { indent_size: 2, space_in_empty_paren: true, indent_empty_lines: true });
2726
}

javascript/jest.config.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919

2020
/** @type {import('ts-jest').JestConfigWithTsJest} */
2121
const semver = require("semver");
22-
const hpsEnable = semver.gt(process.versions.node, '20.0.0') && process.platform !== 'win32';
2322

2423
module.exports = {
25-
collectCoverage: hpsEnable,
24+
collectCoverage: true,
2625
preset: 'ts-jest',
2726
testEnvironment: 'node',
2827
collectCoverageFrom: [
@@ -31,9 +30,6 @@ module.exports = {
3130
"!**/build/**",
3231
"!packages/fury/lib/murmurHash3.ts"
3332
],
34-
"testPathIgnorePatterns" : [
35-
hpsEnable ? null : "(.*)/hps.test.ts$",
36-
].filter(Boolean),
3733
transform: {
3834
'\\.ts$': ['ts-jest', {
3935
tsconfig: {

javascript/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
{
22
"scripts": {
3-
"test": "npm run build && jest",
4-
"clear": "rm -rf ./packages/fury/dist && rm -rf ./packages/hps/dist",
5-
"build": "npm run clear && npm run build -w packages/fury -w packages/hps",
3+
"test": "npm run build && jest && node --expose_externalize_string node_modules/.bin/jest",
4+
"clear": "rm -rf ./packages/fury/dist",
5+
"build": "npm run clear && npm run build -w packages/fury",
66
"lint": "eslint .",
77
"lint-fix": "eslint . --fix"
88
},
99
"repository": "[email protected]:apache/fury.git",
1010
"workspaces": [
11-
"packages/hps",
1211
"packages/fury"
1312
],
1413
"devDependencies": {

javascript/packages/fury/lib/type.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,12 @@ export const HalfMinInt32 = MinInt32 / 2;
9595
export const LATIN1 = 0;
9696
export const UTF8 = 1;
9797

98-
export interface Hps {
99-
isLatin1: (str: string) => boolean;
100-
stringCopy: (str: string, dist: Uint8Array, offset: number) => void;
101-
}
102-
10398
export enum Mode {
10499
SchemaConsistent,
105100
Compatible,
106101
}
107102

108103
export interface Config {
109-
hps?: Hps;
110104
refTracking?: boolean;
111105
useSliceString?: boolean;
112106
hooks?: {

javascript/packages/fury/lib/writer/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ import { PlatformBuffer, alloc, strByteLength } from "../platformBuffer";
2222
import { OwnershipError } from "../error";
2323
import { toFloat16 } from "./number";
2424

25+
declare global {
26+
// eslint-disable-next-line
27+
var isOneByteString: ((input: string) => boolean) | undefined;
28+
}
29+
2530
const MAX_POOL_SIZE = 1024 * 1024 * 3; // 3MB
2631

2732
export class BinaryWriter {
@@ -32,12 +37,10 @@ export class BinaryWriter {
3237
private reserved = 0;
3338
private locked = false;
3439
private config: Config;
35-
private hpsEnable = false;
3640

3741
constructor(config: Config) {
3842
this.initPoll();
3943
this.config = config;
40-
this.hpsEnable = Boolean(config?.hps);
4144
}
4245

4346
private initPoll() {
@@ -188,14 +191,13 @@ export class BinaryWriter {
188191
}
189192

190193
stringOfVarUInt32Fast(v: string) {
191-
const { isLatin1: detectIsLatin1, stringCopy } = this.config.hps!;
192-
const isLatin1 = detectIsLatin1(v);
194+
const isLatin1 = globalThis.isOneByteString!(v);
193195
const len = isLatin1 ? v.length : strByteLength(v);
194196
this.dataView.setUint8(this.cursor++, isLatin1 ? LATIN1 : UTF8);
195197
this.varUInt32(len);
196198
this.reserve(len);
197199
if (isLatin1) {
198-
stringCopy(v, this.platformBuffer, this.cursor);
200+
this.platformBuffer.write(v, this.cursor, "latin1");
199201
} else {
200202
if (len < 40) {
201203
this.fastWriteStringUtf8(v, this.platformBuffer, this.cursor);
@@ -335,7 +337,7 @@ export class BinaryWriter {
335337
}
336338

337339
stringOfVarUInt32(v: string) {
338-
return this.hpsEnable
340+
return globalThis.isOneByteString
339341
? this.stringOfVarUInt32Fast(v)
340342
: this.stringOfVarUInt32Slow(v);
341343
}

javascript/packages/fury/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,5 @@
2525
},
2626
"repository": "[email protected]:apache/fury.git",
2727
"workspaces": [
28-
"packages/hps"
2928
]
3029
}

javascript/packages/hps/README.md

Lines changed: 0 additions & 18 deletions
This file was deleted.

javascript/packages/hps/binding.gyp

Lines changed: 0 additions & 32 deletions
This file was deleted.

javascript/packages/hps/index.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

javascript/packages/hps/package.json

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)