nksaraf / vinxi

The Full Stack JavaScript SDK
https://vinxi.vercel.app
MIT License
2.19k stars 80 forks source link

fix: hash chunks with djb2 #360

Closed katywings closed 2 months ago

katywings commented 2 months ago

This replaces the hashing function with an actual hash algorithm (djb2). The original code comes from https://github.com/sveltejs/svelte/blob/0203eb319b5d86138236158e3ae6ecf29e26864c/packages/svelte/src/utils.js#L7.

I also added a Map to avoid duplicate hashing of earlier inputs.

Comparison of the hashes

[
  { value: 'abc', hashNew: '2nhvp3', hashOld: 294 },
  { value: 'cba', hashNew: '2nhu0v', hashOld: 294 },
  {
    value: '/app/src/server/project.js',
    hashNew: '1gxub3t',
    hashOld: 2526
  },
  {
    value: '/app/src/project/server.js',
    hashNew: '1dkakbx',
    hashOld: 2526
  }
]

Performance

Benchmark wise I didn't do a lot. But the few builds I did on a large project look okay:

SSR Client Server-fns
New 1 8.93s 12.84s 9.40s
New 2 8.73s 13.38s 9.72s
New 3 8.75s 13.06s 9.43s
Median 8.73s 13.06s 9.43s
SSR Client Server-fns
Old 1 9.28s 13.80s 9.43s
Old 2 9.13s 13.23s 9.29s
Old 3 8.87s 13.88s 9.65s
Median 9.13s 13.80s 9.43s
codesandbox[bot] commented 2 months ago

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders
Open Preview

changeset-bot[bot] commented 2 months ago

🦋 Changeset detected

Latest commit: f0a1c26c00ebfefffa9c3695235cf7d68866762d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages | Name | Type | | ------------- | ----- | | vinxi | Patch | | @vinxi/router | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

vercel[bot] commented 2 months ago

@katywings is attempting to deploy a commit to the Nikhil Saraf's projects Team on Vercel.

A member of the Team first needs to authorize it.

pkg-pr-new[bot] commented 2 months ago

commit: f0a1c26

@vinxi/deno-doc

``` pnpm add https://pkg.pr.new/@vinxi/deno-doc@360 ```

vinxi

``` pnpm add https://pkg.pr.new/vinxi@360 ```

@vinxi/plugin-directives

``` pnpm add https://pkg.pr.new/@vinxi/plugin-directives@360 ```

@vinxi/doc

``` pnpm add https://pkg.pr.new/@vinxi/doc@360 ```

@vinxi/plugin-mdx

``` pnpm add https://pkg.pr.new/@vinxi/plugin-mdx@360 ```

@vinxi/openapi

``` pnpm add https://pkg.pr.new/@vinxi/openapi@360 ```

@vinxi/react

``` pnpm add https://pkg.pr.new/@vinxi/react@360 ```

@vinxi/react-server

``` pnpm add https://pkg.pr.new/@vinxi/react-server@360 ```

@vinxi/router

``` pnpm add https://pkg.pr.new/@vinxi/router@360 ```

@vinxi/server-components

``` pnpm add https://pkg.pr.new/@vinxi/server-components@360 ```

@vinxi/server-functions

``` pnpm add https://pkg.pr.new/@vinxi/server-functions@360 ```

@vinxi/solid

``` pnpm add https://pkg.pr.new/@vinxi/solid@360 ```

Open in Stackblitz

vercel[bot] commented 2 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
vinxi-website ❌ Failed (Inspect) Sep 3, 2024 7:04am