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

fix: improve uint64 perf #122

Merged
merged 1 commit into from
Jan 31, 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
1 change: 1 addition & 0 deletions packages/protons-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
"release": "aegir release"
},
"dependencies": {
"uint8-varint": "^2.0.2",
"uint8arraylist": "^2.4.3",
"uint8arrays": "^4.0.6"
},
Expand Down
5 changes: 4 additions & 1 deletion packages/protons-runtime/src/utils/reader.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { decodeUint8Array, encodingLength } from 'uint8-varint'
import { readFloatLE, readDoubleLE } from './float.js'
import { LongBits } from './longbits.js'
import * as utf8 from './utf8.js'
Expand Down Expand Up @@ -304,7 +305,9 @@ export class Uint8ArrayReader implements Reader {
* JavaScript number
*/
uint64Number (): number {
return this.readLongVarint().toNumber(true)
const value = decodeUint8Array(this.buf, this.pos)
this.pos += encodingLength(value)
return value
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/protons-runtime/src/utils/writer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { encodeUint8Array, encodingLength } from 'uint8-varint'
import { allocUnsafe } from 'uint8arrays/alloc'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { writeFloatLE, writeDoubleLE } from './float.js'
Expand Down Expand Up @@ -186,8 +187,7 @@ class Uint8ArrayWriter implements Writer {
* Writes an unsigned 64 bit value as a varint
*/
uint64Number (value: number): this {
const bits = LongBits.fromNumber(value)
return this._push(writeVarint64, bits.length(), bits)
return this._push(encodeUint8Array, encodingLength(value), value)
}

/**
Expand Down