Coder Social home page Coder Social logo

data-ulid's People

Contributors

bbrtj avatar bk avatar chorny avatar esabol avatar szabgab avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

data-ulid's Issues

Open to a re-implementation?

Hi,

I re-wrote parts of the core of Data::ULID to suit my needs. I have two options:

  • take my changes, adjust them to your codebase and send you a PR;
  • put Data::ULID::Faster on CPAN.

This benchmark:

use Benchmark 'cmpthese';
use lib '.';
use ULID       ();
use Data::ULID ();


cmpthese(
  -5,
  { 'ULID text'       => sub { ULID::ulid() },
    'Data::ULID text' => sub { Data::ULID::ulid() },
  }
);

cmpthese(
  -5,
  { 'ULID binary'       => sub { ULID::ulid_bin() },
    'Data::ULID binary' => sub { Data::ULID::binary_ulid() },
  }
);

Gives this results:

                    Rate Data::ULID text       ULID text
Data::ULID text   9456/s              --            -93%
ULID text       145084/s           1434%              --
                      Rate Data::ULID binary       ULID binary
Data::ULID binary   6216/s                --              -99%
ULID binary       805650/s            12860%                --

Do you have any preference? I can do either of the options above.

Thank you,

DateTime dependency may be skipped

This is dependency graph for Data::ULID:
obraz

DateTime dependency tree is huge, and it is only directly used in ulid_date function (not counting isa check in _ulid, as we don't use it there directly).

Would you accept a PR that remove DateTime dependency? How it would work is:

  • during module compilation (in a BEGIN block) we try to load DateTime
  • during ulid_date execution we check whether DateTime was loaded, and we throw exception if it wasn't (something like "using ulid_date function requires DateTime module")
  • in tests, we skip all the tests requiring DateTime if we don't have DateTime installed

Data::ULID::XS

Hey there!

This issue is about something we may consider in the future.

As you know I have worked hard to make the ulid generation faster, and that's because I want to generate them for anything and everything in my performance-hungry project. Sadly I think we are at Perl limits already and ~130k per second may not cut it.

For this reason I am working on partial XS implementation. I have just uploaded Data::ULID::XS - this is very much work in progress, but I already have working pure C base32 encoding. Even with this little XS, ulid can already compete with Crypt::Misc::random_v4uuid:

            Rate    ulid ulid_xs    uuid
ulid    126879/s      --    -60%    -61%
ulid_xs 320655/s    153%      --     -2%
uuid    327762/s    158%      2%      --

I think I can squeeze even more (but not as much) performance out of it when I reimplement binary_ulid in XS.

This module has the same interface as Data::ULID, but will only work for ulid and binary_ulid called without arguments - in other cases it just calls Data::ULID::ulid or Data::ULID::binary_ulid instead. I don't think anything else other than generation needs that much performance. It will also only work for 64 bit systems.

The actual question is - after I fully implement it and make it stable, would you like to include my XS code in base Data::ULID distribution (making Data::ULID::XS obsolete), or keep Data::ULID implemented as-is and let XS implementation coexist?

Another solution would be to make Data::ULID use backends - like JSON::MaybeXS - but the issue I have with this is that Data::ULID already depends on CryptX, which requires XS compilation, so there's technically no reason for it to just ship Perl when XS solution exists (other than Perl code being more stable).

There's no rush, will take me some time to make it stable. Also, I'm not exactly sure if we should do it, because of the limitations mentioned above. I'm perfectly happy with having a second module with XS implementation, but that's not how XS implementations on CPAN usually work.

Fails on 32 bit machines with Math::BigInt < 1.999808

This version check is needed for to_bytes and from_bytes methods and it's fine, but would be nice to avoid smokers reporting a failure. Maybe set this version of Math::BigInt as a dependency even though it won't be used on 64 bit?

ulid_date() should accept timezones

Hi, I've been interested in this module today.
And tried to fix the inconvenience when I use it.

If you like this I'll try to make a PR with the least changes.

the diff is here.

sub ulid_date {
-    my $ulid = shift;
+    my $ulid     = shift;
+    my %args     = @_ if @_ >= 2;
+    my $timezone = shift || 'UTC';
+    $timezone = $args{'time_zone'} if exists $args{'time_zone'};
    die "ulid_date() needs a normal or binary ULID as parameter" unless $ulid;
-    my ($ts, $rand) = _ulid($ulid);
+    my ( $ts, $rand ) = _ulid($ulid);
    $ts = _bint($ts);
-    return DateTime->from_epoch(epoch=>$ts / 1000);
+    return DateTime->from_epoch( epoch => $ts / 1000, time_zone => $timezone );
}

I've just added to accept timezones(and some tidied)

best regard.

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.