lukeed / lukeed/hexoid

not fast nor small

Open
#4 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
205
Forks
7
PR merge metrics
No merged PRs in 30d

Description

Hey, stumbled upon this when I was looking for some docs/middleware that handles POST-payloads for polka.

Bro.. ur code.. it's.. I'm sorry :man_facepalming: a waste of string-ops and entropy...

If you want to minimize LOC have a oneliner:
```js
export const hexoid = len => Array.from(new Array(len)).map(() => ((Math.random() * 0xff) | 0).toString(16)).join('')
```

If you want to target computational efficiency
Then don't throw away all the decimals it's, fresh entropy,
here's a variant that sweeps 8 letters (4bytes) per iteration,
it should be at least 8x faster.

```js
export function hexoid (n = 16) {
let s = ''
for (;n>0; n-=8) s += ((0xffffffff * Math.random()) >>> 0).toString(16), s.length % 2 && (s+='0')
return s.substr(0, s.length + n)
}
```

- The LUT looks fun, not sure it's faster than `toString(16)`
- `Math.random()` is collision-wise a horrible source of random..`randomBytes(8).toString('hex')` works nicer
- Avoiding dynamic allocation speeds things up, when final size is known ahead of time, define your output array/string with set size and use it as working memory.

Thank you this was fun :pray: can you point me in the right direction for parsing payload-data? I wanna go home :cry:

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue does not name a source file, test, or benchmark. Read the repository's current hexoid implementation first, then determine whether the requested change is size or computational efficiency; done should preserve the utility's output behavior while demonstrating the chosen improvement.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.