Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore Concurrency (goroutines and channels) for Copying from Multiple Files #23

Closed
supitsdu opened this issue Jun 26, 2024 · 1 comment · Fixed by #34
Closed

Explore Concurrency (goroutines and channels) for Copying from Multiple Files #23

supitsdu opened this issue Jun 26, 2024 · 1 comment · Fixed by #34
Assignees
Labels
concurrency enhancement New feature requests or enhancements. performance Issues or PRs focused on optimizing Go code performance.

Comments

@supitsdu
Copy link
Owner

When copying content from multiple files, clipper currently processes them sequentially. This might be inefficient, especially when dealing with a large number of files.

We should investigate the use of concurrency with goroutines and channels to parallelize the reading of content from multiple files. This could significantly speed up the copying process in such scenarios.

See:

Tasks:

  1. Design and implement a concurrent solution using goroutines and channels to read content from multiple files simultaneously.
  2. Consider potential synchronization issues and error handling in a concurrent environment.
  3. Benchmark the performance improvement when copying content from multiple files.
  4. Update documentation to explain the use of concurrency.
@supitsdu supitsdu added enhancement New feature requests or enhancements. help wanted Extra attention is needed performance Issues or PRs focused on optimizing Go code performance. concurrency labels Jun 26, 2024
@supitsdu supitsdu self-assigned this Jun 28, 2024
@supitsdu supitsdu added the in-progress Issues or PRs currently being worked on. label Jun 30, 2024
supitsdu added a commit that referenced this issue Jun 30, 2024
…tines and channels

Added new package `cli/reader/reader.go` to handle file and stdin content reading using goroutines and channels. Includes `ReadContentConcurrently` function to improve performance when handling multiple files.

Issue #23
@supitsdu supitsdu removed help wanted Extra attention is needed in-progress Issues or PRs currently being worked on. labels Jun 30, 2024
@supitsdu
Copy link
Owner Author

Performance Comparison Review: Concurrency Improvement in ParseContent Function

Benchmark Results

With Concurrency Improvement
  • Average Time per Operation: 9.03 ms
  • Benchmark Runs: 3
Without Concurrency Improvement
  • Average Time per Operation: 12.95 ms
  • Benchmark Runs: 3

Analysis

The benchmarks demonstrate significant performance gains from the concurrency improvements introduced in PR #34. Here are the key findings:

  • Performance Improvement: The updated ParseContent function, utilizing goroutines and channels for concurrent file reading, achieved an average operation time of 9.03 ms per invocation. This represents a 30% improvement over the previous non-concurrent implementation, which averaged 12.95 ms per operation.

  • Task Completed: Implemented concurrency using goroutines and channels in ParseContent to handle multiple file inputs more efficiently.

Next Steps

  1. Further Optimization: Explore additional optimizations to handle larger file sizes and enhance scalability.
  2. Benchmark Expansion: Extend benchmarking to include scenarios with varying file sizes and concurrency levels to validate performance across different workloads.

Conclusion

PR #34 successfully enhanced the ParseContent function's performance through concurrent file reading, demonstrating tangible benefits in efficiency and responsiveness. This improvement aligns with the project's goal to explore concurrency for better resource utilization and scalability in Clipper.

supitsdu added a commit that referenced this issue Jun 30, 2024
… structure (#34)

* feat(cli/reader): introduce `cli/reader/reader.go` package with goroutines and channels

Added new package `cli/reader/reader.go` to handle file and stdin content reading using goroutines and channels. Includes `ReadContentConcurrently` function to improve performance when handling multiple files.

Issue #23

* refactor(cli/clipper): refactor to use `cli/reader/reader.go` for content reading

Refactored `cli/clipper/clipper.go` to utilize functionalities from `cli/reader/reader.go` package. This change improves code readability and separates concerns for content reading operations.

* test(structure): restructure tests with `tests/tests.go` for helpers and constants

Introduced `tests/tests.go` to hold helper functions and constants used across test cases, improving organization and reusability of testing resources.

* test(reorganize): reorganize `tests/clipper/clipper_test.go` for `cli/clipper/clipper.go` tests

Reorganized `tests/clipper/clipper_test.go` to focus exclusively on testing functionalities within `cli/clipper/clipper.go`, ensuring clear and specific test coverage.

* test(add): implement `tests/reader/reader_test.go` for `cli/reader/reader.go` tests

Introduced `tests/reader/reader_test.go` to contain tests exclusively targeting functionalities within `cli/reader/reader.go`. Enhances clarity and maintainability of test cases related to content reading operations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
concurrency enhancement New feature requests or enhancements. performance Issues or PRs focused on optimizing Go code performance.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant