Skip to content

Refactor copyFile() message fragment for ease of translation - #6483

Merged
MichaelChirico merged 6 commits into
masterfrom
tr-fragments
Sep 8, 2024
Merged

MichaelChirico merged 6 commits into
masterfrom
tr-fragments

Conversation

@MichaelChirico

@MichaelChirico MichaelChirico commented Sep 6, 2024 •

Copy link
Copy Markdown
Member

One part of #6482. The complication here is that we always show the before- and after- message if verbose=True; otherwise, we take care to only flag this to the user if the required file copy is particularly time-consuming (>.5 seconds).

It's also a tad complicated because there's a separation of logic to several places in the code...

That inspired refactoring copyFile() to return the time taken -- now all the messaging logic surrounding copyFile() is all done in one place --> easier to follow.

@MichaelChirico MichaelChirico added the translation issues/PRs related to message translation projects label Sep 6, 2024
@MichaelChirico
MichaelChirico requested a review from aitap September 6, 2024 19:27
@github-actions

github-actions Bot commented Sep 6, 2024 •

Copy link
Copy Markdown

Comparison Plot

Generated via commit 78ad6d8

Download link for the artifact containing the test results: ↓ atime-results.zip

Time taken to finish the standard R installation steps: 11 minutes and 42 seconds

Time taken to run atime::atime_pkg on the tests: 6 minutes and 44 seconds

@MichaelChirico

Copy link
Copy Markdown
Member Author

This approach (pull out the message generation logic from copyFile() helper feels a bit more natural to me, though I do wonder if it's a bit repetitive.

OTOH, it's only called in two places, so it's probably not worth over-thinking how to best modularize here.

Comment thread src/fread.c Outdated
// In future, we may discover a way to mmap fileSize+1 on all OS when fileSize%4096==0, reliably. If and when, this clause can be updated with no code impact elsewhere.
copyFile(fileSize, msg, verbose);
double time_taken = copyFile(fileSize);
if (time_taken < 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In your experience as a professional software developer, does it pay to account for very unlikely corner cases, such as the system clock being very coincidentally adjusted backwards right as copyFile is running? If you think it's too unlikely to care about, that's probably fine.

Maybe we could return NaN on error, but that's a weird error return code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I was vaguely musing if that's possible as I wrote this.

I think we can wait for a user report before fussing here

copyFile should almost never be called. the two cases are (a) one-column files with multiple trailing missing rows and (b) files without trailing newline, in both cases only if the file is an exact multiple of 4096 bytes.

for all that to be true AND the clock to run backwards, it feels like the user is just messing with us :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

one easy way to make this even more impossible to trigger by mistake would be to only check copy file==-1.0 instead of just being negative. then the user would somehow have to have all of the above with an impossibly exact regression of the system time.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If someone manages to trigger exactly that, well, it would be too late to buy lottery tickets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

translation issues/PRs related to message translation projects

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants