{"id":15027546,"url":"https://github.com/discord/fastglobal","last_synced_at":"2025-05-16T15:05:30.975Z","repository":{"id":46699287,"uuid":"82106095","full_name":"discord/fastglobal","owner":"discord","description":"Fast no copy globals for Elixir \u0026 Erlang.","archived":false,"fork":false,"pushed_at":"2023-03-09T21:12:23.000Z","size":8,"stargazers_count":1168,"open_issues_count":13,"forks_count":86,"subscribers_count":40,"default_branch":"master","last_synced_at":"2025-05-11T18:58:55.752Z","etag":null,"topics":["elixir","erlang","performance"],"latest_commit_sha":null,"homepage":"","language":"Elixir","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/discord.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2017-02-15T20:58:14.000Z","updated_at":"2025-05-01T19:34:11.000Z","dependencies_parsed_at":"2022-08-15T12:30:24.426Z","dependency_job_id":"79b6251e-cfa7-4cab-9778-ef5690936dfb","html_url":"https://github.com/discord/fastglobal","commit_stats":null,"previous_names":["hammerandchisel/fastglobal"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discord%2Ffastglobal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discord%2Ffastglobal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discord%2Ffastglobal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/discord%2Ffastglobal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/discord","download_url":"https://codeload.github.com/discord/fastglobal/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254553959,"owners_count":22090417,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["elixir","erlang","performance"],"created_at":"2024-09-24T20:06:39.089Z","updated_at":"2025-05-16T15:05:30.890Z","avatar_url":"https://github.com/discord.png","language":"Elixir","readme":"# FastGlobal\n\n[![Master](https://travis-ci.org/discordapp/fastglobal.svg?branch=master)](https://travis-ci.org/discordapp/fastglobal)\n[![Hex.pm Version](http://img.shields.io/hexpm/v/fastglobal.svg?style=flat)](https://hex.pm/packages/fastglobal)\n\nThe Erlang VM is great at many things, but quick access to large shared data is not one of them. Storing data in a single process\nresults in overloading the process, using an ETS table gets more expensive to read as the data gets larger, and both require copying\ndata to the calling process. If you have large infrequently changing data that needs to be accessed by thousands of processes there\nis a better way.\n\nErlang has an optimization called constant pools for functions that return static data, you can also compile modules at runtime.\nThis method was originally popularized by [mochiglobal](https://github.com/mochi/mochiweb/blob/master/src/mochiglobal.erl). This\nmodule is an Elixir version with some optimizations such as generating the atom keys and reusing them.\n\n## Performance\n\n```\nbenchmark name               iterations   average time\nfastglobal get                 10000000   0.33 µs/op\nets get                          500000   7.64 µs/op\nagent get                        100000   12.67 µs/op\nfastglobal purge perf (100)         500   2846.26 µs/op\nfastglobal put (5)                  500   3683.30 µs/op\nfastglobal put (10)                 500   6449.98 µs/op\nfastglobal put (100)                 50   44543.56 µs/op\n```\n\n## Caveats\n\n- Compile times get slower as data size increases.\n- Compile times get slower the more processes are in the system. Erlang talks to each process when purging a module.\n- Getting a key that does not exist is expensive due to try/catch, put at least a `nil` value.\n- Creating atoms from strings is not cheap, use `FastGlobal.new`.\n\n## Usage\n\nAdd it to `mix.exs`\n\n```elixir\ndefp deps do\n  [{:fastglobal, \"~\u003e 1.0\"}]\nend\n```\n\nAnd just use it as a global map.\n\n```elixir\ndata = %{\n  a: 1,\n  b: 2,\n  c: [3, 4]\n}\nFastGlobal.put(:data, data)\ndata == FastGlobal.get(:data)\n```\n\n## License\n\nFastGlobal is released under [the MIT License](LICENSE).\nCheck [LICENSE](LICENSE) file for more information.\n","funding_links":[],"categories":["\u003ca name=\"Elixir\"\u003e\u003c/a\u003eElixir"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiscord%2Ffastglobal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiscord%2Ffastglobal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiscord%2Ffastglobal/lists"}