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

switch from sha256 to xxh3 #203

Merged
merged 4 commits into from
Jul 4, 2022
Merged

switch from sha256 to xxh3 #203

merged 4 commits into from
Jul 4, 2022

Conversation

vito
Copy link
Owner

@vito vito commented Jul 4, 2022

The main motivation here is UX (shorter identifiers), not performance, though xxh3 is much faster for this use case so I figured I'd try it out.

$ bass
=> (.foo)


        ██████
      ██████████
      ██████████
    ██  ██████  ██
      ██████████
      ██  ██  ██
    ██          ██
      ██      ██

<thunk huuCt5LNZ50=: (.foo)>
=> (path-name (.foo))
"huuCt5LNZ50="

Note: xxh3 is a non-cryptographic hash function. I don't think we need cryptographic properties given how thunk hashes are used:

  • keys in maps for tracking already-loaded Bass modules
  • directory names for thunk paths that are passed in to another thunk in args/env/stdin
  • stringifying the thunk value in the REPL
  • urls in Bass Loop
  • showing it in the page/tab title
  • the hostname of the thunk's container. sidenote: this is what allows labels to bust caches.
  • filenames for cached thunk path exports used for loading Bass source code from a thunk (e.g. git clone of a remote lib)
  • filenames for cached thunk path exports used for rendering backtraces
  • filenames for tmpdirs created by the buildkit runtime during read/export
  • html id= tags in the docs
  • the thunk's (path-name) and (path-stem)

Seems worth noting that secret values contained within a thunk do not influence the thunk's hash:

=> (.foo (mask "yo" :hey))


      ██  ██  ██
      ██████████
    ██  ██████  ██
    ██  ██████  ██
      ██████████
        ██  ██
      ████  ████


<thunk 3OTbj4nXlkM=: (.foo)>
=> (.foo (mask "yoo" :hey))


      ██  ██  ██
      ██████████
    ██  ██████  ██
    ██  ██████  ██
      ██████████
        ██  ██
      ████  ████


<thunk 3OTbj4nXlkM=: (.foo)>
=> (json (.foo (mask "yoo" :hey)))
"{\"cmd\":{\"command\":{\"name\":\"foo\"}},\"stdin\":[{\"secret\":{\"name\":\"hey\"}}]}"

vito added 3 commits July 3, 2022 15:30
sha256 is pretty overkill for how these are used. they're primarily
identifiers; having them shorter makes for better UX.
@vito vito force-pushed the xxhash branch 2 times, most recently from edbe6a9 to aa01857 Compare July 4, 2022 04:34
@vito vito merged commit 75c2ed6 into main Jul 4, 2022
@vito vito deleted the xxhash branch July 4, 2022 04:44
@vito vito added the enhancement New feature or request label Jul 4, 2022
@vito vito mentioned this pull request Aug 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant