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

~2s build time #1602

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
03a5885
re2 regex for BO_ and VAL_ messages
MikeBusuttil Dec 29, 2024
268a89d
old regex fully replaced
MikeBusuttil Dec 29, 2024
0d49db3
install and link re2 (Ubuntu CI only)
MikeBusuttil Dec 29, 2024
75627ee
install and link re2 (Ubuntu CI only)
MikeBusuttil Dec 29, 2024
aa6425c
install and link re2 (Ubuntu CI only)
MikeBusuttil Dec 29, 2024
6322eaf
install re2 (MacOS CI)
MikeBusuttil Dec 29, 2024
3a063e0
debug os-aware library install
MikeBusuttil Dec 29, 2024
ed4dcc3
link re2 (macOS) 🤞
MikeBusuttil Dec 29, 2024
951c72b
WIP: debug macOS re2 linking
MikeBusuttil Dec 29, 2024
9b53af4
auto-install re2 when missing
MikeBusuttil Dec 29, 2024
4f86c54
auto-install re2 when missing
MikeBusuttil Dec 29, 2024
46a4ef5
auto-install re2 when missing
MikeBusuttil Dec 29, 2024
e1700e6
auto-install re2 when missing
MikeBusuttil Dec 29, 2024
bfb11a4
debug masOS re2 linking
MikeBusuttil Dec 29, 2024
c99145c
debug masOS re2 linking 🏳
MikeBusuttil Dec 29, 2024
39c2eb6
readme instructions updated + use all cores
MikeBusuttil Dec 29, 2024
fd2da98
Merge branch 'commaai:master' into fast-build
MikeBusuttil Dec 30, 2024
1235859
raw scons failure fixed by setting PYTHONPATH
MikeBusuttil Dec 30, 2024
69e0c49
cross-platform # of cores
MikeBusuttil Dec 30, 2024
6791968
Merge branch 'scons-fix' into fast-build
MikeBusuttil Dec 30, 2024
9916378
hail mary 🏈
MikeBusuttil Dec 30, 2024
4bcde62
not helpful
MikeBusuttil Dec 30, 2024
6b85f61
🤷‍♂️
MikeBusuttil Dec 30, 2024
240539f
🙏
MikeBusuttil Dec 30, 2024
a5d856b
rollback
MikeBusuttil Dec 30, 2024
df03346
how denied is my permission?
MikeBusuttil Dec 30, 2024
f33756a
🦝
MikeBusuttil Dec 30, 2024
a15f8a1
🔀
MikeBusuttil Dec 30, 2024
82ff6df
got 1 more trick up my sleeve after this
MikeBusuttil Dec 30, 2024
c6ef1c6
RIP git history
MikeBusuttil Dec 30, 2024
e16a67b
just 1 more commit bro
MikeBusuttil Dec 30, 2024
acef6ed
how many opendbc's deep?
MikeBusuttil Dec 30, 2024
30b52c6
just walk away & find someone with a mac
MikeBusuttil Dec 30, 2024
e87b3e6
cython compilation speed boost
MikeBusuttil Dec 30, 2024
9196532
control optimization through env var FAST
MikeBusuttil Dec 30, 2024
42430f0
remote connect to shell🐚
MikeBusuttil Dec 30, 2024
cd8be24
re2 source grab 🖐
MikeBusuttil Dec 30, 2024
4676e4b
let me back in 🐚
MikeBusuttil Dec 30, 2024
f9a67a9
bundle em 📦
MikeBusuttil Dec 30, 2024
9e04607
🐚🗯
MikeBusuttil Dec 30, 2024
918d09f
🐴👀don't look a gift horse in the mouth 🦷✨
MikeBusuttil Dec 30, 2024
f75aca6
no way
MikeBusuttil Dec 30, 2024
9f69a1c
diving back in 🦐🐚
MikeBusuttil Dec 30, 2024
b9b648e
you hate to see it
MikeBusuttil Dec 30, 2024
4d4b898
back to the drawing board 👏🍎
MikeBusuttil Dec 30, 2024
61e0b2f
WoRkSoNmYmAcHiNe💻
MikeBusuttil Dec 30, 2024
c00a433
traverse a different path 👣
MikeBusuttil Dec 30, 2024
9e3a815
🔃
MikeBusuttil Dec 30, 2024
0ce271a
🐚
MikeBusuttil Dec 31, 2024
e2f5557
🐚 back in we go
MikeBusuttil Dec 31, 2024
134408f
🎉💃🥳🎊🎈🎈🎉💃
MikeBusuttil Dec 31, 2024
343056d
allow test.sh to run from anywhere (once again)
MikeBusuttil Dec 31, 2024
91fd548
simpler SG_ regex
MikeBusuttil Jan 11, 2025
2322f57
Don't import unused tools
MikeBusuttil Jan 13, 2025
277ec32
🍎 not again 🍎
MikeBusuttil Jan 13, 2025
887bc73
🍎 shell time?
MikeBusuttil Jan 13, 2025
3cf0fcf
🐚
MikeBusuttil Jan 13, 2025
525dde2
sorry mac users 🍎 not yet
MikeBusuttil Jan 13, 2025
5d54e62
redundant
MikeBusuttil Jan 13, 2025
1867dcd
cleaner
MikeBusuttil Jan 13, 2025
95a90b0
mac linking
MikeBusuttil Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions opendbc/can/dbc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <filesystem>
#include <fstream>
#include <map>
#include <regex>
#include <re2/re2.h>
#include <set>
#include <sstream>
#include <vector>
Expand All @@ -14,11 +14,11 @@
#include "opendbc/can/common.h"
#include "opendbc/can/common_dbc.h"

std::regex bo_regexp(R"(^BO_ (\w+) (\w+) *: (\w+) (\w+))");
std::regex sg_regexp(R"(^SG_ (\w+) : (\d+)\|(\d+)@(\d+)([\+|\-]) \(([0-9.+\-eE]+),([0-9.+\-eE]+)\) \[([0-9.+\-eE]+)\|([0-9.+\-eE]+)\] \"(.*)\" (.*))");
std::regex sgm_regexp(R"(^SG_ (\w+) (\w+) *: (\d+)\|(\d+)@(\d+)([\+|\-]) \(([0-9.+\-eE]+),([0-9.+\-eE]+)\) \[([0-9.+\-eE]+)\|([0-9.+\-eE]+)\] \"(.*)\" (.*))");
std::regex val_regexp(R"(VAL_ (\w+) (\w+) (\s*[-+]?[0-9]+\s+\".+?\"[^;]*))");
std::regex val_split_regexp{R"([\"]+)"}; // split on "
RE2 bo_regexp(R"(^BO_ (\w+) (\w+) *: (\w+) (\w+))");
RE2 sg_regexp(R"(^SG_ (\w+) : (\d+)\|(\d+)@(\d+)([\+|\-]) \(([0-9.+\-eE]+),([0-9.+\-eE]+)\) \[([0-9.+\-eE]+)\|([0-9.+\-eE]+)\] \"(.*)\" (.*))");
RE2 sgm_regexp(R"(^SG_ (\w+) (\w+) *: (\d+)\|(\d+)@(\d+)([\+|\-]) \(([0-9.+\-eE]+),([0-9.+\-eE]+)\) \[([0-9.+\-eE]+)\|([0-9.+\-eE]+)\] \"(.*)\" (.*))");
RE2 val_regexp(R"(VAL_ (\w+) (\w+) (.*))");
RE2 val_split_regexp(R"((([0-9]) \"(.+?)\"))");
Comment on lines +19 to +20
Copy link
Contributor Author

@MikeBusuttil MikeBusuttil Dec 29, 2024

Choose a reason for hiding this comment

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

Notes:

  • no tests match \s*[-+]? so this was removed
  • RE2 doesn't support a variable number of matching groups (the reason for the small refactor here and below)


#define DBC_ASSERT(condition, message) \
do { \
Expand Down Expand Up @@ -121,20 +121,20 @@ DBC* dbc_parse_from_stream(const std::string &dbc_name, std::istream &stream, Ch

std::string line;
int line_num = 0;
std::smatch match;
std::string match1, match2, match3, match4, match5, match6, match7, ignore;
// TODO: see if we can speed up the regex statements in this loop, SG_ is specifically the slowest
while (std::getline(stream, line)) {
line = trim(line);
line_num += 1;
if (startswith(line, "BO_ ")) {
// new group
bool ret = std::regex_match(line, match, bo_regexp);
bool ret = RE2::FullMatch(line, bo_regexp, &match1, &match2, &match3);
DBC_ASSERT(ret, "bad BO: " << line);

Msg& msg = dbc->msgs.emplace_back();
address = msg.address = std::stoul(match[1].str()); // could be hex
msg.name = match[2].str();
msg.size = std::stoul(match[3].str());
address = msg.address = std::stoul(match1); // could be hex
msg.name = match2;
msg.size = std::stoul(match3);

// check for duplicates
DBC_ASSERT(address_set.find(address) == address_set.end(), "Duplicate message address: " << address << " (" << msg.name << ")");
Expand All @@ -146,20 +146,18 @@ DBC* dbc_parse_from_stream(const std::string &dbc_name, std::istream &stream, Ch
}
} else if (startswith(line, "SG_ ")) {
// new signal
int offset = 0;
if (!std::regex_search(line, match, sg_regexp)) {
bool ret = std::regex_search(line, match, sgm_regexp);
if (!RE2::FullMatch(line, sg_regexp, &match1, &match2, &match3, &match4, &match5, &match6, &match7)) {
bool ret = RE2::FullMatch(line, sgm_regexp, &match1, &ignore, &match2, &match3, &match4, &match5, &match6, &match7);
DBC_ASSERT(ret, "bad SG: " << line);
offset = 1;
}
Signal& sig = signals[address].emplace_back();
sig.name = match[1].str();
sig.start_bit = std::stoi(match[offset + 2].str());
sig.size = std::stoi(match[offset + 3].str());
sig.is_little_endian = std::stoi(match[offset + 4].str()) == 1;
sig.is_signed = match[offset + 5].str() == "-";
sig.factor = std::stod(match[offset + 6].str());
sig.offset = std::stod(match[offset + 7].str());
sig.name = match1;
sig.start_bit = std::stoi(match2);
sig.size = std::stoi(match3);
sig.is_little_endian = std::stoi(match4) == 1;
sig.is_signed = match5 == "-";
sig.factor = std::stod(match6);
sig.offset = std::stod(match7);
set_signal_type(sig, checksum, dbc_name, line_num);
if (sig.is_little_endian) {
sig.lsb = sig.start_bit;
Expand All @@ -176,21 +174,23 @@ DBC* dbc_parse_from_stream(const std::string &dbc_name, std::istream &stream, Ch
signal_name_sets[address].insert(sig.name);
} else if (startswith(line, "VAL_ ")) {
// new signal value/definition
bool ret = std::regex_search(line, match, val_regexp);
bool ret = RE2::FullMatch(line, val_regexp, &match1, &match2, &match3);
DBC_ASSERT(ret, "bad VAL: " << line);

auto& val = dbc->vals.emplace_back();
val.address = std::stoul(match[1].str()); // could be hex
val.name = match[2].str();
val.address = std::stoul(match1); // could be hex
val.name = match2;

auto defvals = match[3].str();
std::sregex_token_iterator it{defvals.begin(), defvals.end(), val_split_regexp, -1};
auto defvals = match3;
// convert strings to UPPER_CASE_WITH_UNDERSCORES
std::vector<std::string> words{it, {}};
for (auto& w : words) {
w = trim(w);
std::transform(w.begin(), w.end(), w.begin(), ::toupper);
std::replace(w.begin(), w.end(), ' ', '_');
std::vector<std::string> words;
std::string full_match, number, word;
while (RE2::PartialMatch(defvals, val_split_regexp, &full_match, &number, &word)) {
word = trim(word);
std::transform(word.begin(), word.end(), word.begin(), ::toupper);
std::replace(word.begin(), word.end(), ' ', '_');
words.push_back(number + " " + word);
defvals = defvals.substr(full_match.length(), defvals.length() - full_match.length());
}
// join string
std::stringstream s;
Expand Down
Loading