Giter VIP home page Giter VIP logo

uuid's Introduction

uuid Build Status

This library is useful for creating, comparing, parsing and printing Universally Unique Identifiers. See http://en.wikipedia.org/wiki/UUID for the general idea.

We offer two different packages: uuid and uuid-types

The uuid package aims to be a fully-featured library for working with UUIDs.

However if you're developing a library and only want the UUID type to show up in your APIs you may want to use the uuid-types library to minimize the number of dependencies needed by users of your library.

uuid's People

Contributors

23skidoo avatar alexanderkjeldaas avatar artemshitov avatar aslatter avatar bardurarantsson avatar basvandijk avatar bitonic avatar chris-martin avatar hesselink avatar hvr avatar mzero avatar pearcedavis avatar phadej avatar prikhi avatar tvh avatar werehamster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

uuid's Issues

We should test that 'fromFoo' functions are stable across releases

We offer many functions such as fromString, fromByteString and fromWords which, given the same input should always produce the same resultant UUID.

We should hard-code some inputs and UUIDs into our tests to verify that changes to the library do not result in changes to how we generate UUIDs from fixed-inputs.

This, plus our round-trip tests, should also be enough to test that for a fixed UUID our toFoo functions are also stable.

GHC 8.4.x compatibility

uuid doesn't work with GHC-8.4.x.

uuid currently depends on entropy < 0.4 (0.3.8) which doesn't support GHC-8.4.x due to its setup script failing to parse ghc-pkg's output.

Iiuc #36 attempts to fix this.

Currently this is work-aroundable using the --allow-newer=entropy cabal flag.

More compact internal representation

Currently, UUID is represented as

data UUID  = UUID
         {-# UNPACK #-} !Word32
         {-# UNPACK #-} !Word32
         {-# UNPACK #-} !Word32
         {-# UNPACK #-} !Word32

However, this suboptimal for 64bit archs (where GHC currently stores this a 320-byte Heap object); would you accept a PR switching to the internal representation (which is represented by GHC as 192-byte Heap objects on 64bit archs, also Ord/Eq operations would be more efficient)

data UUID  = UUID
         {-# UNPACK #-} !Word64
         {-# UNPACK #-} !Word64

?

This could either be made unconditional, or CPP-conditional on whether Int/Word is 64bit or 32bit wide.

toText / fromText

The text package doesn't have any crazy dependencies, and since you already depend on bytestring it isn't too crazy to support text as well.

another way to generate UUID without using getEntropy ?

Hi,
I'm heavily using nextRandom (V4) and I have exhausted the resources :

 /dev/urandom: openFd: resource exhausted (Too many open files)

I didn't know you were using getEntropy behind :

-- On some platforms this requies a file handle which can lead to resource
-- exhaustion in some situations.
getEntropy :: Int               -- ^ Number of bytes
           -> IO B.ByteString
getEntropy = bracket openHandle closeHandle . flip hGetEntropy

Can't we have something not using the file system ?

Unable to obtain V1 UUID once limit of 3fff is reached

The source of version 1.3.13 says

stepTime = do
  h1 <- fmap hundredsOfNanosSinceGregorianReform getCurrentTime
  modifyMVar state $ \s@(State mac' c0 h0) ->
   if h1 > h0
    then
      return (State mac' c0 h1, Just (mac', c0, h1))
    else
      let
        c1 = succ c0
      in if c1 <= 0x3fff -- when clock is initially randomized,
                      -- then this test will need to change
         then
          return (State mac' c1 h1, Just (mac', c1, h1))
        else
          return (s, Nothing)

Since c0 is never reset to 0 it seems that once 3fff is reached - i.e. after requesting a V1 UUID too fast 3fff times - no new V1 UUID will ever be returned.

Maybe the first return line should read (note the 0 instead of c0)

      return (State mac' 0 h1, Just (mac', 0, h1))

Or is there a reason for this behaviour, e.g. some specification that demands this?

Can't install uuid on macOS

When I install uuid by adding uuid to my stack package.yaml, I get the following error:

tohash-md5-0.11.101.0/In file included from /var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/ghc27215_0/ghc_16.c:4:0: error:
cryptohash-md5 >
cryptohash-md5 >
cryptohash-md5 > In file included from /Users/nsadeh/.stack/programs/aarch64-osx/ghc-9.0.2/lib/ghc-9.0.2/lib/../lib/aarch64-osx-ghc-9.0.2/rts-1.0.2/include/ffi.h:66:0: error:
cryptohash-md5 >
cryptohash-md5 >
cryptohash-md5 > /Users/nsadeh/.stack/programs/aarch64-osx/ghc-9.0.2/lib/ghc-9.0.2/lib/../lib/aarch64-osx-ghc-9.0.2/rts-1.0.2/include/ffitarget.h:6:10: error:
cryptohash-md5 >      fatal error: 'ffitarget_arm64.h' file not found
cryptohash-md5 >   |
cryptohash-md5 > 6 | #include "ffitarget_arm64.h"
cryptohash-md5 >   |          ^
cryptohash-md5 > #include "ffitarget_arm64.h"
cryptohash-md5 >          ^~~~~~~~~~~~~~~~~~~
cryptohash-md5 > 1 error generated.
cryptohash-md5 > `gcc' failed in phase `C Compiler'. (Exit code: 1)
cryptohash-sha1> build
entropy        > configure
cryptohash-sha1> Preprocessing library for cryptohash-sha1-0.11.101.0..
cryptohash-sha1> Building library for cryptohash-sha1-0.11.101.0..
entropy        > [1 of 2] Compiling Main             ( /private/var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/stack-69879577c11930dd/entropy-0.4.1.10/Setup.hs, /private/var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/stack-69879577c11930dd/entropy-0.4.1.10/.stack-work/dist/aarch64-osx/Cabal-3.4.1.0/setup/Main.o )
cryptohash-sha1> [1 of 3] Compiling Compat
cryptohash-sha1> [2 of 3] Compiling Crypto.Hash.SHA1.FFI
cryptohash-sha1>
cryptohash-sha1> /private/var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/stack-69879577c11930dd/cryptohash-sha1-0.11.101.0/In file included from /var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/ghc27406_0/ghc_16.c:4:0: error:
cryptohash-sha1>
cryptohash-sha1>
cryptohash-sha1> In file included from /Users/nsadeh/.stack/programs/aarch64-osx/ghc-9.0.2/lib/ghc-9.0.2/lib/../lib/aarch64-osx-ghc-9.0.2/rts-1.0.2/include/ffi.h:66:0: error:
cryptohash-sha1>
cryptohash-sha1>
cryptohash-sha1> /Users/nsadeh/.stack/programs/aarch64-osx/ghc-9.0.2/lib/ghc-9.0.2/lib/../lib/aarch64-osx-ghc-9.0.2/rts-1.0.2/include/ffitarget.h:6:10: error:
cryptohash-sha1>      fatal error: 'ffitarget_arm64.h' file not found
cryptohash-sha1>   |
cryptohash-sha1> 6 | #include "ffitarget_arm64.h"
cryptohash-sha1>   |          ^
cryptohash-sha1> #include "ffitarget_arm64.h"
cryptohash-sha1>          ^~~~~~~~~~~~~~~~~~~
cryptohash-sha1> 1 error generated.
cryptohash-sha1> `gcc' failed in phase `C Compiler'. (Exit code: 1)
entropy        > [2 of 2] Compiling StackSetupShim   ( /Users/nsadeh/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /private/var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/stack-69879577c11930dd/entropy-0.4.1.10/.stack-work/dist/aarch64-osx/Cabal-3.4.1.0/setup/StackSetupShim.o )
entropy        > Linking /private/var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/stack-69879577c11930dd/entropy-0.4.1.10/.stack-work/dist/aarch64-osx/Cabal-3.4.1.0/setup/setup ...
entropy        > Configuring entropy-0.4.1.10...
entropy        > build
hashable       > configure
entropy        >
entropy        > /private/var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/stack-69879577c11930dd/entropy-0.4.1.10/testRDRAND-27943/testRDRAND.c:6:24: error:
entropy        >      error: invalid output constraint '=qm' in asm
entropy        >          : "=r" (therand), "=qm" (err));
entropy        >                            ^
entropy        >   |
entropy        > 6 |      : "=r" (therand), "=qm" (err));
entropy        >   |                        ^
entropy        > 1 error generated.
entropy        > `gcc' failed in phase `C Compiler'. (Exit code: 1)
entropy        > Result of RDRAND Test: False
entropy        >
entropy        > /private/var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/stack-69879577c11930dd/entropy-0.4.1.10/testLibcGetrandom-27943/testLibcGetrandom.c:7:12: error:
entropy        >      error: implicit declaration of function 'getrandom' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
entropy        >         return getrandom(&tmp, sizeof(tmp), GRND_NONBLOCK) != -1;
entropy        >                ^
entropy        >   |
entropy        > 7 |     return getrandom(&tmp, sizeof(tmp), GRND_NONBLOCK) != -1;
entropy        >   |            ^
entropy        >
entropy        > /private/var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/stack-69879577c11930dd/entropy-0.4.1.10/testLibcGetrandom-27943/testLibcGetrandom.c:7:41: error:
entropy        >      error: use of undeclared identifier 'GRND_NONBLOCK'
entropy        >         return getrandom(&tmp, sizeof(tmp), GRND_NONBLOCK) != -1;
entropy        >                                             ^
entropy        >   |
entropy        > 7 |     return getrandom(&tmp, sizeof(tmp), GRND_NONBLOCK) != -1;
entropy        >   |                                         ^
entropy        > 2 errors generated.
entropy        > `gcc' failed in phase `C Compiler'. (Exit code: 1)
entropy        > Result of libc getrandom() Test: False
entropy        >
entropy        > /private/var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/stack-69879577c11930dd/entropy-0.4.1.10/testSyscallGetrandom-27943/testSyscallGetrandom.c:6:10: error:
entropy        >      fatal error: 'linux/random.h' file not found
entropy        >   |
entropy        > 6 | #include <linux/random.h>
entropy        >   |          ^
entropy        > #include <linux/random.h>
entropy        >          ^~~~~~~~~~~~~~~~
entropy        > 1 error generated.
entropy        > `gcc' failed in phase `C Compiler'. (Exit code: 1)
entropy        > Result of syscall getrandom() Test: False
entropy        >
entropy        > /private/var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/stack-69879577c11930dd/entropy-0.4.1.10/testGetentropy-27943/testGetentropy.c:6:12: error:
entropy        >      error: implicit declaration of function 'getentropy' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
entropy        >         return getentropy(&tmp, sizeof(tmp));
entropy        >                ^
entropy        >   |
entropy        > 6 |     return getentropy(&tmp, sizeof(tmp));
entropy        >   |            ^
entropy        > 1 error generated.
entropy        > `gcc' failed in phase `C Compiler'. (Exit code: 1)
entropy        > Result of getentropy() Test: False
entropy        > Preprocessing library for entropy-0.4.1.10..
entropy        > Building library for entropy-0.4.1.10..
hashable       > Configuring hashable-1.3.5.0...
entropy        > [1 of 2] Compiling System.EntropyNix
hashable       > build
network-info   > configure
hashable       > Preprocessing library for hashable-1.3.5.0..
hashable       > Building library for hashable-1.3.5.0..
entropy        >
entropy        > /private/var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/stack-69879577c11930dd/entropy-0.4.1.10/In file included from /var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/ghc28066_0/ghc_7.c:4:0: error:
entropy        >
entropy        >
entropy        > In file included from /Users/nsadeh/.stack/programs/aarch64-osx/ghc-9.0.2/lib/ghc-9.0.2/lib/../lib/aarch64-osx-ghc-9.0.2/rts-1.0.2/include/ffi.h:66:0: error:
entropy        >
entropy        >
entropy        > /Users/nsadeh/.stack/programs/aarch64-osx/ghc-9.0.2/lib/ghc-9.0.2/lib/../lib/aarch64-osx-ghc-9.0.2/rts-1.0.2/include/ffitarget.h:6:10: error:
entropy        >      fatal error: 'ffitarget_arm64.h' file not found
entropy        >   |
entropy        > 6 | #include "ffitarget_arm64.h"
entropy        >   |          ^
entropy        > #include "ffitarget_arm64.h"
entropy        >          ^~~~~~~~~~~~~~~~~~~
entropy        > 1 error generated.
entropy        > `gcc' failed in phase `C Compiler'. (Exit code: 1)
hashable       > [1 of 7] Compiling Data.Hashable.Imports
hashable       >
hashable       > /private/var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/stack-69879577c11930dd/hashable-1.3.5.0/src/Data/Hashable/Imports.hs:1:1: warning: [-Wmissing-safe-haskell-mode]
hashable       >     Data.Hashable.Imports is missing Safe Haskell mode
hashable       >   |
hashable       > 1 | -- | This module exists to avoid conditional imports
hashable       >   | ^
hashable       > [2 of 7] Compiling Data.Hashable.LowLevel
network-info   > Configuring network-info-0.2.1...
hashable       >
hashable       > /private/var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/stack-69879577c11930dd/hashable-1.3.5.0/In file included from /var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/ghc28232_0/ghc_20.c:4:0: error:
hashable       >
hashable       >
hashable       > In file included from /Users/nsadeh/.stack/programs/aarch64-osx/ghc-9.0.2/lib/ghc-9.0.2/lib/../lib/aarch64-osx-ghc-9.0.2/rts-1.0.2/include/ffi.h:66:0: error:
hashable       >
hashable       >
hashable       > /Users/nsadeh/.stack/programs/aarch64-osx/ghc-9.0.2/lib/ghc-9.0.2/lib/../lib/aarch64-osx-ghc-9.0.2/rts-1.0.2/include/ffitarget.h:6:10: error:
hashable       >      fatal error: 'ffitarget_arm64.h' file not found
hashable       >   |
hashable       > 6 | #include "ffitarget_arm64.h"
hashable       >   |          ^
hashable       > #include "ffitarget_arm64.h"
hashable       >          ^~~~~~~~~~~~~~~~~~~
hashable       > 1 error generated.
hashable       > `gcc' failed in phase `C Compiler'. (Exit code: 1)
network-info   > build
splitmix       > configure
network-info   > Preprocessing library for network-info-0.2.1..
network-info   > Building library for network-info-0.2.1..
network-info   > [1 of 1] Compiling Network.Info
splitmix       > Configuring splitmix-0.1.0.4...
network-info   >
network-info   > /private/var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/stack-69879577c11930dd/network-info-0.2.1/src/Network/Info.hsc:46:10: warning: [-Wmissing-methods]
network-info   >     • No explicit implementation for
network-info   >         either ‘poke’ or ‘pokeElemOff’ or ‘pokeByteOff’
network-info   >     • In the instance declaration for ‘Storable NetworkInterface’
network-info   >    |
network-info   > 46 | instance Storable NetworkInterface where
network-info   >    |          ^^^^^^^^^^^^^^^^^^^^^^^^^
splitmix       > build
splitmix       > Preprocessing library for splitmix-0.1.0.4..
splitmix       > Building library for splitmix-0.1.0.4..
network-info   >
network-info   > /private/var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/stack-69879577c11930dd/network-info-0.2.1/In file included from /var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/ghc28602_0/ghc_3.c:4:0: error:
network-info   >
network-info   >
network-info   > In file included from /Users/nsadeh/.stack/programs/aarch64-osx/ghc-9.0.2/lib/ghc-9.0.2/lib/../lib/aarch64-osx-ghc-9.0.2/rts-1.0.2/include/ffi.h:66:0: error:
network-info   >
network-info   >
network-info   > /Users/nsadeh/.stack/programs/aarch64-osx/ghc-9.0.2/lib/ghc-9.0.2/lib/../lib/aarch64-osx-ghc-9.0.2/rts-1.0.2/include/ffitarget.h:6:10: error:
network-info   >      fatal error: 'ffitarget_arm64.h' file not found
network-info   >   |
network-info   > 6 | #include "ffitarget_arm64.h"
network-info   >   |          ^
network-info   > #include "ffitarget_arm64.h"
network-info   >          ^~~~~~~~~~~~~~~~~~~
network-info   > 1 error generated.
network-info   > `gcc' failed in phase `C Compiler'. (Exit code: 1)
splitmix       > [1 of 4] Compiling Data.Bits.Compat
splitmix       > [2 of 4] Compiling System.Random.SplitMix.Init
splitmix       >
splitmix       > /private/var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/stack-69879577c11930dd/splitmix-0.1.0.4/In file included from /var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/ghc28664_0/ghc_22.c:4:0: error:
splitmix       >
splitmix       >
splitmix       > In file included from /Users/nsadeh/.stack/programs/aarch64-osx/ghc-9.0.2/lib/ghc-9.0.2/lib/../lib/aarch64-osx-ghc-9.0.2/rts-1.0.2/include/ffi.h:66:0: error:
splitmix       >
splitmix       >
splitmix       > /Users/nsadeh/.stack/programs/aarch64-osx/ghc-9.0.2/lib/ghc-9.0.2/lib/../lib/aarch64-osx-ghc-9.0.2/rts-1.0.2/include/ffitarget.h:6:10: error:
splitmix       >      fatal error: 'ffitarget_arm64.h' file not found
splitmix       >   |
splitmix       > 6 | #include "ffitarget_arm64.h"
splitmix       >   |          ^
splitmix       > #include "ffitarget_arm64.h"
splitmix       >          ^~~~~~~~~~~~~~~~~~~
splitmix       > 1 error generated.
splitmix       > `gcc' failed in phase `C Compiler'. (Exit code: 1)
Progress 6/10

--  While building package splitmix-0.1.0.4 (scroll up to its section to see the error) using:
      /Users/nsadeh/.stack/setup-exe-cache/aarch64-osx/Cabal-simple_mPHDZzAJ_3.4.1.0_ghc-9.0.2 --builddir=.stack-work/dist/aarch64-osx/Cabal-3.4.1.0 build --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1


--  While building package network-info-0.2.1 (scroll up to its section to see the error) using:
      /Users/nsadeh/.stack/setup-exe-cache/aarch64-osx/Cabal-simple_mPHDZzAJ_3.4.1.0_ghc-9.0.2 --builddir=.stack-work/dist/aarch64-osx/Cabal-3.4.1.0 build --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1


--  While building package hashable-1.3.5.0 (scroll up to its section to see the error) using:
      /Users/nsadeh/.stack/setup-exe-cache/aarch64-osx/Cabal-simple_mPHDZzAJ_3.4.1.0_ghc-9.0.2 --builddir=.stack-work/dist/aarch64-osx/Cabal-3.4.1.0 build --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1


--  While building package entropy-0.4.1.10 (scroll up to its section to see the error) using:
      /private/var/folders/cz/bh5dm65s0_lf7_0pb1v27v200000gn/T/stack-69879577c11930dd/entropy-0.4.1.10/.stack-work/dist/aarch64-osx/Cabal-3.4.1.0/setup/setup --builddir=.stack-work/dist/aarch64-osx/Cabal-3.4.1.0 build --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1


--  While building package cryptohash-sha1-0.11.101.0 (scroll up to its section to see the error) using:
      /Users/nsadeh/.stack/setup-exe-cache/aarch64-osx/Cabal-simple_mPHDZzAJ_3.4.1.0_ghc-9.0.2 --builddir=.stack-work/dist/aarch64-osx/Cabal-3.4.1.0 build --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1


--  While building package cryptohash-md5-0.11.101.0 (scroll up to its section to see the error) using:
      /Users/nsadeh/.stack/setup-exe-cache/aarch64-osx/Cabal-simple_mPHDZzAJ_3.4.1.0_ghc-9.0.2 --builddir=.stack-work/dist/aarch64-osx/Cabal-3.4.1.0 build --ghc-options " -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1

Is there an incompatibility with Apple silicon? My machine is a Macbook Pro 13" M1 (2020).

Data.UUID.V1 MAC number should be configurable

Systems can have multiple non-trivial MAC addresses. There should be an option to choose which one to use in UUID V1 generation, instead of taking the first one which getNetworkInterfaces returns.

toString got slower

Benchmark                  old       old2              master             master2          
HashSet making             0.376e-5  0.378e-5  +0.66%  0.438e-5  +16.65%  0.433e-5  +15.31%
Set making                 0.424e-5  0.430e-5  +1.29%  0.399e-5   -6.03%  0.397e-5   -6.37%
conversion/fromASCIIBytes  2.541e-7  2.254e-7 -11.30%  2.258e-7  -11.13%  2.160e-7  -14.99%
conversion/fromByteString  0.684e-7  0.748e-7  +9.42%  0.762e-7  +11.46%  0.748e-7   +9.38%
conversion/fromString      0.476e-6  0.492e-6  +3.39%  0.488e-6   +2.52%  0.515e-6   +8.31%
conversion/fromText        0.777e-6  0.809e-6  +4.05%  0.284e-6  -63.44%  0.265e-6  -65.85%
conversion/fromWords       0.609e-8  0.612e-8  +0.49%  0.633e-8   +3.98%  0.613e-8   +0.65%
conversion/toASCIIBytes    0.344e-7  0.305e-7 -11.23%  0.327e-7   -4.83%  0.385e-7  +11.91%
conversion/toByteString    1.058e-7  1.075e-7  +1.67%  1.058e-7   +0.07%  1.065e-7   +0.73%
conversion/toString        3.037e-7  3.077e-7  +1.34%  6.320e-7 +108.12%  6.394e-7 +110.57%
conversion/toText          0.550e-6  0.514e-6  -6.58%  0.050e-6  -90.84%  0.055e-6  -89.94%
conversion/toWords         0.898e-8  0.890e-8  -0.93%  0.864e-8   -3.77%  0.844e-8   -5.96%
storable/peek              2.936e-8  2.842e-8  -3.21%  2.925e-8   -0.38%  2.823e-8   -3.85%
storable/poke              0.509e-8  0.524e-8  +2.97%  0.492e-8   -3.23%  0.498e-8   -2.14%
testing/compare differ     0.718e-8  0.731e-8  +1.78%  0.694e-8   -3.39%  0.718e-8   -0.02%
testing/compare same       0.834e-8  0.867e-8  +3.94%  0.713e-8  -14.52%  0.725e-8  -13.10%
testing/eq differ          0.698e-8  0.707e-8  +1.37%  0.678e-8   -2.76%  0.679e-8   -2.72%
testing/eq same            0.679e-8  0.687e-8  +1.18%  0.707e-8   +4.14%  0.703e-8   +3.53%
testing/null nil           0.417e-8  0.419e-8  +0.48%  0.328e-8  -21.50%  0.325e-8  -22.14%
testing/null nil2          0.490e-8  0.481e-8  -1.90%  0.413e-8  -15.84%  0.418e-8  -14.64%
testing/null non-nil       0.353e-8  0.347e-8  -1.89%  0.291e-8  -17.70%  0.278e-8  -21.26%
Geometric mean             0.465e-7  0.464e-7  -0.26%  0.395e-7  -15.07%  0.397e-7  -14.62%

old is 953aef9

Otherwise change to Word64 (and other changes) are overall improvement.

Also a picture so you can see highlights

Screenshot from 2021-02-16 23-35-19

My machine is noisy as you can see from differences of two runs, so +-10% is fine (on individual benchmark)

v4 UUIDs are not that random

There are 2122 possible random (v4) UUIDs. Data.UUID.V4.nextRandom uses randomIO to generate them, which uses StdGen. StdGen has 64 bits of internal state (two Int32s), so there can only be at the most 264 different UUIDs generated by nextRandom, which is a lot less than 2122.

Additionally, StdGen is not cryptographically secure: observing one UUID is enough to compute all the next ones. I know they are not required to be (by the RFC), but I can find many examples of people using UUIDs as session tokens in cookies, where being able to compute the next UUID could allow someone to take over another account. Most other UUID libraries I've seen to use a CSPRNG to generate v4 UUIDs.

binary-0.8

Hi!

The upper bound on binary prevents binary 0.8 to be used with uuid-types.

Cheers!

Hackage Release

The uuid-types library has seen some pretty important performance improvements in the last three years, but none of these have been released to hackage. It would be nice to see a new release.

Conversion to and from mixed-endian byte strings

Microsoft tends to encode UUIDs in a mixed-endian format.

"Other systems, notably Microsoft's marshalling of UUIDs in their COM/OLE libraries, use a mixed-endian format, whereby the first three components of the UUID are little-endian, and the last two are big-endian."

There's plenty of evidence of this. Ask me how I know 😉

It'd be useful if the uuid library also provided conversions to and from this format. I created this conversion to ByteString:

toMixedEndianByteString :: UUID -> ByteString
toMixedEndianByteString uuid =
    case BS.unpack $ toByteString uuid of
      [w0,w1,w2,w3, w4,w5, w6,w7, w8,w9, wa,wb,wc,wd,we,wf] ->
        BS.pack [w3,w2,w1,w0, w5,w4, w7,w6, w8,w9, wa,wb,wc,wd,we,wf]
      _ -> BS.empty

I've yet to attempt the reverse conversion, but I think it'll look similar.

Is there any interest in getting this into the library? If so, I'll be happy to attempt a pull request.

Fix tests on GHC 7.4

Commit 8a517d3 introduced builds with Travis.

However Out testing routines don't compile against GHC 7.4.

I think supporting 7.4 is not crazy, so if it's easy to do so we should.

Error:

tests/TestUUID.hs:91:45:
    No instance for (Data.String.IsString BL.ByteString)
      arising from the literal `"\165\202\133f\217\197H5\153\200\225\241>s\181\226"'
    Possible fix:
      add an instance declaration for
      (Data.String.IsString BL.ByteString)
    In the first argument of `U.fromByteString', namely
      `"\165\202\133f\217\197H5\153\200\225\241>s\181\226"'
    In the second argument of `(@=?)', namely
      `U.fromByteString
         "\165\202\133f\217\197H5\153\200\225\241>s\181\226"'
    In the second argument of `(~:)', namely
      `Just inputUUID
       @=?
         U.fromByteString
           "\165\202\133f\217\197H5\153\200\225\241>s\181\226"'
The command "cabal configure --enable-tests && cabal build && cabal test" exited with 1.
Done. Your build exited with 1.

https://travis-ci.org/aslatter/uuid/jobs/45593970

Same UUID generated by processes started at precisely the same time

This causes spurious errors in a test-suite which spawns numerous processes. I don't see a very direct way to use the UUID library in a way that reliably generates unique identifiers. Perhaps the implementation should be changed to handle this circumstance?

Repro steps:

  1. Have a fast computer? Might not repro for everyone.
  2. git clone https://github.com/mgsloan/uuid-v4-collision-repro.git
  3. stack build
  4. stack exec uuid-v4-collision-repro-exe-2

Results:

...
Iteration #143
766fd3c5-b3d9-4df4-b845-a6ae45c0a903
766fd3c5-b3d9-4df4-b845-a6ae45c0a903
uuid-v4-collision-repro-exe-2: UUID collision!

Support for time-1.9

It has some nice additions and I'd like to use it in my projects. Seems to build correctly, but I did not review the changes

Support GHC-9.6

Compiling yields:

[__1] trying: uuid-1.3.15 (dependency of amazonka)
[__2] trying: uuid-types-1.0.5 (dependency of uuid)
[__3] next goal: template-haskell (dependency of uuid-types)
[__3] rejecting: template-haskell-2.20.0.0/installed-2.20.0.0 (conflict:
uuid-types => template-haskell>=2.7.0.0 && <2.20)

Allow-newer seems to work, so a revision would be sufficient.

Arbitrary

I searched a bit but couldn't find any implementation of Arbitrary for UUID, to easily use it on QuickCheck (or generate mocks on servant!). If there's none, do you have any tip on how it should be done?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.