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

Miracle Grue .jsontoolpath stream reader #9

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

scottsha
Copy link
Contributor

@scottsha scottsha commented Nov 10, 2023

Need to read .makerbot print command files.

The typical miracle grue .makerbot format contains an ascii text json file with a list of json dict entry for each command.

The currently used json reader does not have a streamable json parser, which means the entire json file has to be read into memory at once. For even moderately sized prints this can cause an out of memory crash. This stream is slower than directly one-shot reading the file, though not necessarily asymptotically slower. See comparison below. Note that one-shot reading is really not an option due to the size constraints. Minute long read times are rough to handle.

This command streamer is intended to parse a single command at a time, and does so by tracking {} depth. Alternatives:

  • find a usable json parser that allows for streamability. Boost might?

`"test/data/icos_lava/print.jsontoolpath"
num commands: 98521
Sream read time: 1441ms
One-shot read time: 851ms

"shirleys_good_mask_cura_30oct_MMXL/print.jsontoolpath"
num commands: 2154012
Sream read time: 24332ms
One-shot read in: 19542ms

"magma-support1-absr-rr-nov3/print.jsontoolpath"
num commands: 4847882
Sream read time: 64591ms
One-shot read in: NA out of memory segfault`

Copy link

github-actions bot commented Nov 10, 2023

Unit Test Results

0 tests  ±0   0 ✔️ ±0   0s ⏱️ ±0s
1 suites ±0   0 💤 ±0 
1 files   ±0   0 ±0 

Results for commit a6bc3f0. ± Comparison against base commit 289b5c4.

♻️ This comment has been updated with latest results.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ clang-tidy found issue(s) with the introduced code (1/1)

{
break;
}
end_char = buffer->sbumpc();

Choose a reason for hiding this comment

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

⚠️ bugprone-narrowing-conversions ⚠️
narrowing conversion from std::basic_streambuf<char>::int_type (aka int) to signed type char is implementation-defined

std::string CommandFileStream::getCommandLine()
{
std::string line;
if (! stream.is_open())

Choose a reason for hiding this comment

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

⚠️ google-readability-braces-around-statements ⚠️
statement should be inside braces

Suggested change
if (! stream.is_open())
if (! stream.is_open()) {

{
std::string line;
if (! stream.is_open())
return line;

Choose a reason for hiding this comment

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

⚠️ google-readability-braces-around-statements ⚠️
statement should be inside braces

Suggested change
return line;
return line;
}

if (last_char == CommandFileStream::K_CMD_CLOSE)
{
bracket_depth--;
if (bracket_depth <= 0)

Choose a reason for hiding this comment

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

⚠️ google-readability-braces-around-statements ⚠️
statement should be inside braces

Suggested change
if (bracket_depth <= 0)
if (bracket_depth <= 0) {

{
bracket_depth--;
if (bracket_depth <= 0)
return line;

Choose a reason for hiding this comment

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

⚠️ google-readability-braces-around-statements ⚠️
statement should be inside braces

Suggested change
return line;
return line;
}

EXPECT_EQ(command_lines.size(), 7);
}

TEST(miracle_jtp_tests, command_stream)

Choose a reason for hiding this comment

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

⚠️ google-readability-avoid-underscore-in-googletest-name ⚠️
avoid using "_" in test name "command_stream" according to Googletest FAQ

}


TEST(miracle_jtp_tests, command_stream_vs_oneshot)

Choose a reason for hiding this comment

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

⚠️ cppcoreguidelines-owning-memory ⚠️
initializing non-owner argument of type testing::internal::TestFactoryBase * with a newly created gsl::owner<>

}


TEST(miracle_jtp_tests, command_stream_vs_oneshot)

Choose a reason for hiding this comment

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

⚠️ google-readability-avoid-underscore-in-googletest-name ⚠️
avoid using "_" in test case name "miracle_jtp_tests" according to Googletest FAQ

}


TEST(miracle_jtp_tests, command_stream_vs_oneshot)

Choose a reason for hiding this comment

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

⚠️ google-readability-avoid-underscore-in-googletest-name ⚠️
avoid using "_" in test name "command_stream_vs_oneshot" according to Googletest FAQ


// check types
EXPECT_EQ(cmd_list_from_stream.size(), cmd_list_from_oneshot.size());
for (size_t cmd_ii = 0; cmd_ii < cmd_list_from_stream.size(); cmd_ii++)

Choose a reason for hiding this comment

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

⚠️ altera-id-dependent-backward-branch ⚠️
backward branch (for loop) is ID-dependent due to variable reference to cmd_list_from_stream and may cause performance degradation

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.

1 participant