{"id":18769799,"url":"https://github.com/buarki/primes-finder","last_synced_at":"2026-04-20T03:02:15.147Z","repository":{"id":218470765,"uuid":"746428935","full_name":"buarki/primes-finder","owner":"buarki","description":"A simple app that implements the Sieve of Eratosthenes using Go and WebAssembly","archived":false,"fork":false,"pushed_at":"2024-03-24T19:52:33.000Z","size":448,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-11T02:34:14.901Z","etag":null,"topics":["go","vercel","wasm","webassembly"],"latest_commit_sha":null,"homepage":"https://primes-finder.vercel.app","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/buarki.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-01-22T00:59:07.000Z","updated_at":"2024-01-22T03:11:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"4d987bd4-cdbc-4fa7-bfc2-32f18f326db8","html_url":"https://github.com/buarki/primes-finder","commit_stats":null,"previous_names":["buarki/primes-finder"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/buarki/primes-finder","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buarki%2Fprimes-finder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buarki%2Fprimes-finder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buarki%2Fprimes-finder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buarki%2Fprimes-finder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/buarki","download_url":"https://codeload.github.com/buarki/primes-finder/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buarki%2Fprimes-finder/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32031070,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-20T00:18:06.643Z","status":"online","status_checked_at":"2026-04-20T02:00:06.527Z","response_time":94,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["go","vercel","wasm","webassembly"],"created_at":"2024-11-07T19:16:56.951Z","updated_at":"2026-04-20T03:02:15.112Z","avatar_url":"https://github.com/buarki.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# primes finder\n\n## WebAssembly\n\nThis project was created to check the state of [WebAssembly](https://webassembly.org/) development tools now, in the beginning of 2024, specifically with Go programing language.\n\nSo far, I was able to put this project to run by digging into the [provided documentation](https://github.com/golang/go/wiki/WebAssembly#getting-started), but it was not a straightforward process, especially in terms of passing complex objects from Go to Javascript level. I'll need to study it more :)\n\n## Sieve of Eratosthenes\n\nThe [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) is an algorithm very useful for finding prime numbers up to a given limit. For instance, if you ask for all the prime numbers up to 12 you'll have 2, 3, 5, 7 and 11.\n\nThe ideia is very simple:\n- we create a list of numbers with the size of the given limit + 1 (just to be able to represent the numbers using indexes);\n- we assume that all numbers in such a list are truly prime numbers;\n- as we know that 0 and 1 are not prime numbers we mark them as false;\n- then, we iterate from 2 up to the square root of the given limit checking if the current number can divide the limit, if so we mark all multiples of the current number as false;\n- and then we repeat this process;\n\nThe implemention of this algorithm can be found at the [find_primes.go](cmd/wasm//find_primes.go), such implementation has a time complexity of **O(n log log n)** and space complexity of **O(n)**.\n\n## How this project works?\n\nThis project has two main parts:\n- the WebAssembly binary [written in go](/cmd/wasm/main.go);\n- the [Javascript client](public/index.html) that uses the WebAssembly binary;\n\n### The Go part\n\nThe [Go part](/cmd/wasm/main.go) is a simple program that makes a Go function called **findPrimes** available at the Javascript level when running in a WebAssembly environment. This is done bellow line:\n\n```go\njs.Global().Set(\"findPrimes\", findPrimes())\n```\n\nIt also defines simple channel to prevent the program from exiting immediately. This is typical in WebAssembly programs where the Go runtime does not automatically wait for asynchronous tasks. This is done by bellow line:\n\n```go\n\u003c-make(chan bool)\n```\n\nTo build this project the prepared command **gowasm* at the [Makefile](./Makefile) can be used, and behind the scenes it does bellow:\n\n```go\nGOARCH=wasm GOOS=js go build -o public/main.wasm cmd/wasm/*.go\n```\n\nAnd another important file is the **wasm_exec.js**, already provided by Go, thus we just need to copy it. The Makefile also has the command **wasm_exec** to do it out of the box, but behind the scenes it runs this:\n\n```go\ncp \"$(go env GOROOT)/misc/wasm/wasm_exec.js\" public/wasm_exec.js\n```\n\nWith files **wasm_exec.js** and **main.wasm** available we can load them on the Javascript client to call the function **findPrimes**.\n\nEverytime the button **Find** is pressed a function is called to collect the limit given by user to validate it and if valid to execute **findPrimes**. With the found prime numbers available, they are rendered as an unordered list.\n\n### The Javascript part\n\nThis one is relatively simple, [it just an HTML file with inline Javascript](public/index.html) to receive the limit to be used to perform the Sieve of Eratosthenes and call the function **findPrimes** provided by Go.\n\n## Running Locally\n\nThis repository has a [Makefile](./Makefile) with a `local` command that will be in charge of building needed stuff and starting the server on port 8080, to use just run bellow command:\n\n```sh\nmake local\n```\n\n## The deploy to production using Vercel\n\nVercel now [supports Go functions](https://vercel.com/docs/functions/serverless-functions/runtimes/go), and due to the easy integration this project is deployed [there](https://primes-finder.vercel.app/).\n\nThere's just one small note on this: in order to make the files [public/main.wasm](./public/main.wasm) and [/public/wasm_exec.js](/public/wasm_exec.js) available from [public/index.html](public/index.html) we need to strip the prefix **/public**, due to that the script [adjust-index.sh](./adjust-index.sh) was built and is configured to be run on Vercel during the release.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuarki%2Fprimes-finder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbuarki%2Fprimes-finder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuarki%2Fprimes-finder/lists"}