Take shortcut when inserting simple ascii while in ground state
One of the things that worked well for me in a prototype external to VTE was around how data was ingested from the PTY. In particular, to get things really fast required avoiding hitting the parser tables at all for much of the input. For many bulk cases we can assume a fairly simple character set from 0x20..0x7f, which while in the GROUND state could allow for shortcuts.
One simple way to get part way there today would be to scan ahead in the process_incoming_utf8()
loop. Unfortunately, this works a lot better when you don't have to copy data into the ring rows (and instead reference chunk fragments from the ring row), but it's still good for a few percent CPU savings.
No worries if you don't want to do this, but figured I'd at least start a convo on tightening up the PTY ingestion/parsing.
diff --git a/src/parser-glue.hh b/src/parser-glue.hh
index e4f1d236..00dd925f 100644
--- a/src/parser-glue.hh
+++ b/src/parser-glue.hh
@@ -68,6 +68,11 @@ public:
vte_parser_ignore_until_st(&m_parser);
}
+ inline bool is_ground () const noexcept
+ {
+ return m_parser.state == 0; // STATE_GROUND
+ }
+
protected:
vte_parser_t m_parser;
}; // class Parser
diff --git a/src/vte.cc b/src/vte.cc
index 60c18fd7..4c6782ec 100644
--- a/src/vte.cc
+++ b/src/vte.cc
@@ -3648,6 +3648,21 @@ Terminal::process_incoming_utf8(ProcessingContext& context,
while (ip < iend) {
+ if G_LIKELY (m_parser.is_ground()) {
+ if (ip < iend && *ip >= 0x20 && *ip <= 0x7f) {
+ context.pre_GRAPHIC(*this);
+
+ while (ip < iend && *ip >= 0x20 && *ip <= 0x7f) {
+ insert_char (*ip, false, false);
+ ip++;
+ }
+
+ context.post_GRAPHIC(*this);
+
+ continue;
+ }
+ }
+
switch (m_utf8_decoder.decode(*(ip++))) {
case vte::base::UTF8Decoder::REJECT_REWIND:
/* Rewind the stream.