Home / Function/ buildDefaultGenReqId() — fastify Function Reference

buildDefaultGenReqId() — fastify Function Reference

Architecture documentation for the buildDefaultGenReqId() function in req-id-gen-factory.js from the fastify codebase.

Entity Profile

Dependency Diagram

graph TD
  958f34ba_77ee_38c6_d869_331084c72169["buildDefaultGenReqId()"]
  a459b50d_6bda_52b1_6093_9868b8f762c9["req-id-gen-factory.js"]
  958f34ba_77ee_38c6_d869_331084c72169 -->|defined in| a459b50d_6bda_52b1_6093_9868b8f762c9
  5d6bfca2_7a09_3a50_8649_149055835528["reqIdGenFactory()"]
  5d6bfca2_7a09_3a50_8649_149055835528 -->|calls| 958f34ba_77ee_38c6_d869_331084c72169
  style 958f34ba_77ee_38c6_d869_331084c72169 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

lib/req-id-gen-factory.js lines 28–41

function buildDefaultGenReqId () {
  // 2,147,483,647 (2^31 − 1) stands for max SMI value (an internal optimization of V8).
  // With this upper bound, if you'll be generating 1k ids/sec, you're going to hit it in ~25 days.
  // This is very likely to happen in real-world applications, hence the limit is enforced.
  // Growing beyond this value will make the id generation slower and cause a deopt.
  // In the worst cases, it will become a float, losing accuracy.
  const maxInt = 2147483647

  let nextReqId = 0
  return function defaultGenReqId () {
    nextReqId = (nextReqId + 1) & maxInt
    return `req-${nextReqId.toString(36)}`
  }
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does buildDefaultGenReqId() do?
buildDefaultGenReqId() is a function in the fastify codebase, defined in lib/req-id-gen-factory.js.
Where is buildDefaultGenReqId() defined?
buildDefaultGenReqId() is defined in lib/req-id-gen-factory.js at line 28.
What calls buildDefaultGenReqId()?
buildDefaultGenReqId() is called by 1 function(s): reqIdGenFactory.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free