hardikm9850 / Go-Playground

1 stars 0 forks source link

GoLang learning plan #1

Open hardikm9850 opened 1 month ago

hardikm9850 commented 1 month ago

GoLang learning plan suggested by @abhishekbodhekar

✅ 1. go through the complete go-tour ✅ 2. Concurrency: Learn about goroutines, channels, and the sync package (waitgroups) ✅ 3. Error handling - with errors.New(), errors.Join(), erros.Is() etc ✅ 4. Interfaces: how an interface in Go can be used with different purposes (including empty interface) ✅ 5. Reflection ✅ 6. Generics ⌛️ 7. Testing
⌛️ 8. Profiling and Benchmarking ⌛️ 9. Dependency Management here ✅ 10. How a go binary is built? (What actually happens behind the scene) ✅ 11. How Go's garbage collection is done? (What method/algo is uses)

  1. How come go's binary is comparatively built faster and smaller?
  2. How go scheduler works behind the scene?
  3. go vendoring
  4. go tools such as (fmt, vet , list etc)
  5. Context package
  6. Middleware

Cheatsheet

hardikm9850 commented 1 month ago

Go binary build process

go_build_process_

Explanation:

Developer: Initiates the build process using the go build command with the source code file (main.go in this example).

GoCompiler: Takes over the compilation process:

  1. Parsing: Reads and parses the .go files, checking for syntax errors and building an AST.
  2. Type Checking: Ensures type correctness across the codebase.
  3. IR Generation: Converts the AST into an intermediate representation (IR).
  4. Optimization: Performs various optimizations on the IR to improve performance and reduce size.
  5. Code Generation: Translates the optimized IR into machine code specific to the target architecture.

GoLinker: Manages the linking process:

  1. Resolving Symbols: Matches symbols (function calls, variable references) with their definitions across different object files and libraries.
  2. Combining Object Files: Merges all compiled object files (including the Go runtime) into a single executable binary.
  3. Generating Executable: Prepares the final executable binary with an entry point (main function) and necessary runtime support.

Developer: Receives the final output from the linker, which is the executable binary (main in this case), ready for deployment and execution

hardikm9850 commented 1 month ago

Garbage collection

gc

Explanation:

  1. Allocate Memory: When the program allocates memory for new objects, Go decides whether to store them in the young generation (if they are young objects) or the old generation (if they are older or have survived previous collections).

  2. Program Execution: The program continues to execute normally, and memory allocation and usage continue.

  3. Garbage Collection Needed?: Periodically, Go checks if garbage collection is necessary based on factors like heap size, allocation rates, and memory pressure.

  4. Stop The World (STW): During garbage collection, there are brief STW phases:

  1. Sweeping: After marking, Go sweeps through memory regions to reclaim memory from unreachable objects.

  2. Compaction (optional): If enabled (GOGC environment variable), Go may optionally compact the heap after sweeping to reduce fragmentation and improve memory locality.

  3. Resume Program Execution: After garbage collection and optional compaction, the program resumes execution.