From 49d04a81cd20330aa41e1cfa533c1567724eb181 Mon Sep 17 00:00:00 2001 From: Stefan Bischof Date: Thu, 22 Oct 2026 19:37:19 +0200 Subject: [PATCH] perf(ccc): do not build the CongoCC tree The ccc grammar builds the record model in its actions and never reads the CongoCC parse tree, which was built and discarded on every parse (about a sixth of the CPU, a third of the allocations). TREE_BUILDING_ENABLED = false leaves it out; the wrapper drops its trace-level tree dump and reads error positions from Token directly. FoodMart corpus, 257 statements, JDK 25, old and new in both orders: warm 63-72 -> 36-41 us per statement, first statement in a fresh JVM 125-127 -> 103-110 ms, first pass 1249-1303 -> 905-957 us per statement. TCK green (213 tests), the model of every corpus statement is unchanged. Signed-off-by: Stefan Bischof --- parser.ccc/src/main/ccc/Grammer.ccc | 1 + .../mdx/parser/ccc/MdxParserWrapper.java | 31 ++----------------- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/parser.ccc/src/main/ccc/Grammer.ccc b/parser.ccc/src/main/ccc/Grammer.ccc index 8db3524..4253ed2 100644 --- a/parser.ccc/src/main/ccc/Grammer.ccc +++ b/parser.ccc/src/main/ccc/Grammer.ccc @@ -22,6 +22,7 @@ NODE_PACKAGE = org.eclipse.daanse.mdx.parser.ccc.tree; TABS_TO_SPACES = 4; PRESERVE_TABS = true; NODE_PREFIX = "AST"; +TREE_BUILDING_ENABLED = false; COPYRIGHT_BLURB="\n*\n* Copyright (c) 2023 Contributors to the Eclipse Foundation.\n*\n* This program and the accompanying materials are made\n* available under the terms of the Eclipse Public License 2.0\n* which is available at https://www.eclipse.org/legal/epl-2.0/\n*\n* SPDX-License-Identifier: EPL-2.0\n*\n* Contributors: see corresponding .ccc file\n"; INJECT PARSER_CLASS : diff --git a/parser.ccc/src/main/java/org/eclipse/daanse/mdx/parser/ccc/MdxParserWrapper.java b/parser.ccc/src/main/java/org/eclipse/daanse/mdx/parser/ccc/MdxParserWrapper.java index 2b62d97..988e46e 100644 --- a/parser.ccc/src/main/java/org/eclipse/daanse/mdx/parser/ccc/MdxParserWrapper.java +++ b/parser.ccc/src/main/java/org/eclipse/daanse/mdx/parser/ccc/MdxParserWrapper.java @@ -15,9 +15,6 @@ import java.util.List; import java.util.Optional; -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.nio.charset.StandardCharsets; import java.util.Set; import org.slf4j.Logger; @@ -99,8 +96,6 @@ public MdxStatement parseMdxStatement() throws MdxParserException { } catch (StackOverflowError e) { logger.debug("Failed to parse, nested too deep"); throw tooDeep(e); - } finally { - dump(); } } @@ -118,11 +113,11 @@ private static MdxParserException toMdxParserException(ParseException pe) { * text does not have. The statement ends right after its last token, so that is where it is reported. */ private static MdxParserException atToken(ParseException pe) { - Node.TerminalNode token = pe.getToken(); + Token token = pe.getToken(); String message = pe.getMessage(); int line = token.getBeginLine(); int column = token.getBeginColumn(); - Token last = token instanceof Token eof && eof.getType() == Token.TokenType.EOF ? eof.getPrevious() : null; + Token last = token.getType() == Token.TokenType.EOF ? token.getPrevious() : null; if (last != null) { line = last.getEndLine(); column = last.getEndColumn() + 1; @@ -132,26 +127,6 @@ private static MdxParserException atToken(ParseException pe) { return new MdxParserException(message, pe, line, column); } - private void dump() { - // Node.dump() writes the whole tree to System.out, so it has to be gated on the - // level like the message above it. Ungated, every parse printed its AST: ~177k - // lines per TCK test group, unreachable by any logging configuration. - if (!logger.isTraceEnabled()) { - return; - } - Node root = delegate.rootNode(); - if (root != null) { - // through the logger, not to System.out: the configuration decides where it goes - try { - ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - root.dump("", new PrintStream(buffer, false, StandardCharsets.UTF_8)); - logger.trace("parser AST:{}{}", System.lineSeparator(), buffer.toString(StandardCharsets.UTF_8)); - } catch (StackOverflowError e) { - logger.trace("parser AST is nested too deep to dump"); - } - } - } - /** * Every failure of a parse is a MdxParserException, also the stack that runs * out on input the nesting limit of the grammar did not stop. @@ -276,8 +251,6 @@ private T parse(String what, ParseAction action) throws MdxParserExceptio } catch (StackOverflowError e) { logger.debug("Failed to parse, nested too deep"); throw tooDeep(e); - } finally { - dump(); } } }