{"id":16038125,"url":"https://github.com/byroot/thread_hazardous","last_synced_at":"2026-04-28T19:02:36.094Z","repository":{"id":25394707,"uuid":"28823386","full_name":"byroot/thread_hazardous","owner":"byroot","description":"Monkey patch thread_safe to make it faster in non thread safe applications","archived":false,"fork":false,"pushed_at":"2015-01-05T18:13:28.000Z","size":144,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-31T00:14:35.658Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/byroot.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-01-05T17:30:08.000Z","updated_at":"2016-01-14T04:14:39.000Z","dependencies_parsed_at":"2022-08-24T06:30:12.622Z","dependency_job_id":null,"html_url":"https://github.com/byroot/thread_hazardous","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/byroot/thread_hazardous","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byroot%2Fthread_hazardous","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byroot%2Fthread_hazardous/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byroot%2Fthread_hazardous/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byroot%2Fthread_hazardous/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/byroot","download_url":"https://codeload.github.com/byroot/thread_hazardous/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/byroot%2Fthread_hazardous/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32394478,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T14:34:11.604Z","status":"ssl_error","status_checked_at":"2026-04-28T14:32:37.009Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-08T22:40:29.014Z","updated_at":"2026-04-28T19:02:36.058Z","avatar_url":"https://github.com/byroot.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ThreadHazardous\n\n[![Build Status](https://travis-ci.org/byroot/thread_hazardous.svg)](http://travis-ci.org/byroot/thread_hazardous)\n[![Gem Version](https://badge.fury.io/rb/thread_hazardous.png)](http://badge.fury.io/rb/byroot/thread_hazardous)\n\nMonkey patch thread_safe to make it faster in non thread safe applications\n\n**CAUTION: Use this gem at your own risk.**\n\nIf you use gems that depends on the `thread_safe` gem,\ne.g. Rails, but your application is not doing any threading, then `thread_hazardous` can bring you a few performance\nimprovements at the cost of making these dependencies non thread safe.\n\n## Explanation\n\n`ThreadSafe::Cache` on MRI to provide thread safety wrap all it's method in a mutex.\nAlso to ensure the cache won't be modified during an iteration, it clones the instance. So each iteration allocate an extra object.\n\n\nThese operations themselves are not that costly, but they are often used in heavy hotspots, especially in Rails, so in the end it adds up.\nHere's a profiling real life application under real life load:\n\n```\n==================================\n  Mode: wall(1000)\n  Samples: 15836 (0.35% miss rate)\n  GC: 696 (4.40%)\n==================================\nTOTAL (pct)   SAMPLES (pct)   FRAME\n419   (2.6%)    419   (2.6%)  ThreadSafe::NonConcurrentCacheBackend#[]\n208   (1.3%)    208   (1.3%)  ThreadSafe::NonConcurrentCacheBackend#dupped_backend\n 75   (0.5%)     75   (0.5%)  block in ThreadSafe::Cache#values\n```\n\n\n`thread_hazardous` simply monkey patch `ThreadSafe::Cache` to remove the mutex and not clone the instance on iteration.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'thread_hazardous'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install thread_hazardous\n\n## Usage\n\nNothing more to do, it's all automatic.\n\n## Contributing\n\n1. Fork it ( https://github.com/byroot/thread_hazardous/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyroot%2Fthread_hazardous","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbyroot%2Fthread_hazardous","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyroot%2Fthread_hazardous/lists"}