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

Challenge: stazrouti submission #143

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stazrouti
Copy link

No description provided.

const fs = require('fs');

// Reading the input.txt file
fs.readFile('../../input.txt', 'utf8', (err, data) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loads the whole file in memory I believe. It can trigger ab OOM

Copy link
Author

@stazrouti stazrouti Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aboullaite
but the memory usage is not indicated in the requirement !!

angry

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its 22G of data! There is no such thing as infinite memory

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aboullaite
but there is no need for a lot of ressources

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading the whole file in memory would require 22G, plus the overhead of any data structure to handle your code, and then everything else. That's a lot of memory

Copy link
Author

@stazrouti stazrouti Feb 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aboullaite
sorry but no need for 22 G, i try it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am no nodejs expert, but this article and many others point to that readFile load file in memory https://betterprogramming.pub/a-memory-friendly-way-of-reading-files-in-node-js-a45ad0cc7bb6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants