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

integrate isDeflate and isGzip #230

Merged
merged 5 commits into from
Jun 13, 2022

Conversation

Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Jun 11, 2022

integrate isDeflate and isGzip
remove corresponding packages from dependencies
wrote unit tests for the above functions

Checklist

remove corresponding packages from dependencies
write unit tests for the above functions
lib/utils.js Show resolved Hide resolved
@Uzlopak Uzlopak requested review from Fdawgs and Eomm June 12, 2022 21:07
@Uzlopak Uzlopak requested review from Fdawgs and kibertoad June 13, 2022 09:40
@Uzlopak
Copy link
Contributor Author

Uzlopak commented Jun 13, 2022

@kibertoad
@Fdawgs

I have to ask you to again review it. On a smoking break I realized that i can do the CMF header check in isDeflate with bit operations.

before:

valid x 223,947,412 ops/sec ±0.70% (90 runs sampled)
invalid x 831,593,213 ops/sec ±0.88% (93 runs sampled)

after:

valid x 1,027,199,609 ops/sec ±0.74% (89 runs sampled)
invalid x 1,038,269,211 ops/sec ±0.94% (91 runs sampled)
'use strict'

const { Suite } = require('benchmark')
const isDeflate = require('./lib/utils').isDeflate

const suite = new Suite()

const fakeDeflate = Buffer.from([0x78, 0x9d])
const fakeGzip = Buffer.from(Buffer.from([0x1f, 0x8b, 0x08]))

suite.add('valid', function () {
  isDeflate(fakeDeflate)
}).add('invalid', function () {
  isDeflate(fakeGzip)
})
suite
  .on('cycle', function (event) {
    console.log(String(event.target))
  })
  .on('complete', function () {
    console.log('Fastest is ' + this.filter('fastest').map('name'))
    console.log('Slowest is ' + this.filter('slowest').map('name'))
  })
  .run({ async: true })

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina mcollina merged commit 142ecb6 into fastify:master Jun 13, 2022
@Uzlopak Uzlopak deleted the integrate-isDeflate-isGzip branch August 17, 2022 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants