Coder Social home page Coder Social logo

Thread safety about hashids.net HOT 23 CLOSED

ullmark avatar ullmark commented on May 31, 2024
Thread safety

from hashids.net.

Comments (23)

ullmark avatar ullmark commented on May 31, 2024 1

@Exocomp there are no maintainers in plural, only me sadly. I would however be very happy if someone would make a PR with those test cases. I recently had a kid and have had rather limited spare time.. I will get there and create those tests, but maybe not as soon as you'd like!

from hashids.net.

manigandham avatar manigandham commented on May 31, 2024 1

Hey everyone - the latest release 1.4.0 is now live: https://www.nuget.org/packages/Hashids.net/1.4.0

from hashids.net.

manigandham avatar manigandham commented on May 31, 2024

We use it in millions of calls every minute in a multithreaded app using a static singleton instance. It works fine as-is.

There are lots of other performance improvements that we made for allocations though in our internal fork but you should be fine as far as thread-safety.

from hashids.net.

Exocomp avatar Exocomp commented on May 31, 2024

@manigandham thanks for chiming in, that's reassuring.

For the library maintainers I suggest creating some test cases for thread safety of all the methods just be sure, the performance of a single instance is just too good just to limit this library to always create a new instance. It will only add to the awesomeness of this library.

from hashids.net.

Exocomp avatar Exocomp commented on May 31, 2024

@ullmark thank you for creating this library it is super useful! Congrats on your child and I absolutely understand regarding time. I'm super busy also but hopefully sometime in the future we can find some time.

from hashids.net.

MrSmoke avatar MrSmoke commented on May 31, 2024

@manigandham any chance of upstreaming some of those performance updates into this repo?

from hashids.net.

manigandham avatar manigandham commented on May 31, 2024

@MrSmoke Sure but it's been years since I worked on our fork and it needs to be redone with the latest language features.

@Daramant has an open PR for better performance right now: #37

from hashids.net.

ullmark avatar ullmark commented on May 31, 2024

So, the deal is that I don't really use windows much these last years, I'm going to see if I can get it running in macOs and .net core. Otherwise I might be able to remote to a windows computer.

Its great to hear @manigandham, but are there a way to really test thread safety? When this ticket came in I tried googling how to verify that in .net, but couldn't really find anything good?

I would gladly accept someone to contribute to this library and give push/publish access as well, as I've asked earlier.

from hashids.net.

manigandham avatar manigandham commented on May 31, 2024

You can test by creating new threads that call the same instance and use Thread.Join to wait for the results. Add in some randomization to the loops and it should be enough for the logic being tested here.

Also the older target frameworks can probably be dropped since they're end of life already, and .NET Framework 4.8 is the last/latest Windows framework which already supports netstandard2.0. This is the latest guidance: https://docs.microsoft.com/en-us/dotnet/standard/library-guidance/cross-platform-targeting

I can help as a contributor, let me know

from hashids.net.

ullmark avatar ullmark commented on May 31, 2024

@manigandham I'll give you access! 👍

from hashids.net.

manigandham avatar manigandham commented on May 31, 2024

@ullmark Got it, thanks. I'll see what I can do in the next few days

from hashids.net.

Daramant avatar Daramant commented on May 31, 2024

I'd appreciate if you can confirm thread safety for this library, due to performance gains its worth using a single instance instead of just creating a new instance every time.

HashIds store simple data types inside and don't modify it. So, yes, it is thread safe.
Added thread safe test: 5e7d43d

from hashids.net.

manigandham avatar manigandham commented on May 31, 2024

hey @ullmark

I merged a bunch of bug fixes and improvements, updated tests, added the github actions workflow, and updated library version to 2.0.0. It should be ready for publishing to nuget. Let me know.

from hashids.net.

Daramant avatar Daramant commented on May 31, 2024

Hi, @manigandham, final optimizations: #43

from hashids.net.

ullmark avatar ullmark commented on May 31, 2024

@manigandham let me just briefly explain my thoughts on versioning of this library. This is initially a port of a javascript (or PHP whichever was first) library that now exists in 40+ languages. One of my friends built the Ruby version so I would say the code base is influenced by his port.

I tried to make build it by taking influences from JS to make sure that any changes to the algorithm could be made to .net version as easy as possible, ensuring that a hash created in one language could be used in another given the settings are the same.

At first I followed the versioning of the other libraries, but as where I added features like "long"-support that made no sense in for instance javascript, I started bumping minor version when I added non breaking stuff.

As for these updates I see no reason for updating major version since it doesn't have any breaking changes or big new features?

from hashids.net.

manigandham avatar manigandham commented on May 31, 2024

@ullmark Ah, thanks for the explanation - that makes sense. I'll merge in the new PR by @Daramant which made some more improvements in reducing allocations and will reset the version number to 1.4.0 (since we haven't published it yet).

from hashids.net.

ullmark avatar ullmark commented on May 31, 2024

@manigandham going to see if I can give you access to publish on nuget as well.

from hashids.net.

manigandham avatar manigandham commented on May 31, 2024

Impressive results from @Daramant

Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
RoundtripInts 3.958 us 0.0559 us 0.0523 us 0.0687 - - 576 B
RoundtripLongs 4.546 us 0.0470 us 0.0439 us 0.0687 - - 576 B
RoundtripHex 4.095 us 0.0503 us 0.0470 us 0.1755 - - 1512 B

Build and tests all pass: https://github.com/ullmark/hashids.net/runs/2411647475

@ullmark all set to release version 1.4.0

from hashids.net.

manigandham avatar manigandham commented on May 31, 2024

hi @ullmark are you still planning on publishing? anything I can do to help?

from hashids.net.

ullmark avatar ullmark commented on May 31, 2024

hi @manigandham. A question; Is there any way of using github for that, seeing a couple of new panels. Otherwise I could add so you have access publishing on nuget, what's your account there?

from hashids.net.

ullmark avatar ullmark commented on May 31, 2024

seeing microsoft now owns github right, it should be possible to setup something that deploys directly to nuget? (since I don't really use windows anymore... )

from hashids.net.

manigandham avatar manigandham commented on May 31, 2024

There's nothing automatic in github. It supports package hosting but separately from nuget. There are github actions that can push to nuget but I havent set that up before.

My nuget username is https://www.nuget.org/profiles/manigandham

from hashids.net.

ullmark avatar ullmark commented on May 31, 2024

@manigandham I created a new Organization called "hashids.net" on nuget where I also invited you as a collaborator. I removed myself as owner of the package and let the organization be the only owner.

I believe you should be able to publish new versions of the package now. Feel free to email me at [email protected] in the future if there is something you want to discuss. There is also a "hashids" organization on Github, I can ask them to invite you, but to be honest, not much is happening there 😄

from hashids.net.

Related Issues (20)

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.