Repository navigation
Conversation
…name findMatchingFunctions and findMatchingFunctionsAndGenerics walked every module of the library for each unqualified name and probed its function and generic tables, though a name lives in a few modules. With many modules required that walk is most of the lookup. InferTypes keeps, per name hash, the modules that define a function or a generic of that name, in library order, built on the first lookup of the name in the pass. The module being compiled is always in the list: new instances land there during the pass. Qualified names keep the walk. examples/dasLLAMA/run.das (17436 functions), instructions inside inferTypes on one P-core: 141.7G before, 119.2G after (-16%); infer 103.7 s -> 82.5 s, whole compile 240 s -> 215 s.
… list ModuleLibrary::hasFunctionOrGenericNamed summed every module's nameGeneration on each call to check its cache, and the cache dropped whenever any module gained a name - which the module being compiled does all through infer. The four infer callers now ask the module being compiled directly and the per-name module list for the rest, and the library cache, its three fields and Module::nameGeneration go. examples/dasLLAMA/run.das, instructions inside inferTypes on one P-core: 119.2G before, 118.0G after.
gc_id only names a node in GC diagnostics (error reports, DAS_GC_BREAK_ON_ID), so 32 bits are enough; the global id counter stays 64-bit. Every AST node is 8 bytes smaller. A static_assert pins the 64-bit size.
Expression drops printFlags, 8 bytes per node. ExprBracketLevels in ast_boost collects the expressions an infix emitter prints without brackets; the AOT emitters and ast_print read it, so ast_print stops bracketing every operator. ast_print_flags and the unused Program::setPrintFlags go away; the serializer version moves to 312.
…alias findAlias and findFuncAlias asked every global of the module for the alias before falling back to the type name, once per lookup. A module with many globals pays that walk on every call whose name is not yet resolved, though almost no lookup ends at a global. InferTypes keeps, per pass, the globals whose type holds an alias or is still auto or an alias, rebuilt when the module's global count moves. dasllama_vulkan_classes: 248k lookups, the globals walk 17.6 s -> 0.56 s.
checkSideEffects runs two whole-module visitors and is called before every constant-folding, CSE and dead-store pass of every optimization round, though most calls follow passes that changed nothing. The flags stay valid until astChanged(), the same signal the access flags already key on. dasllama_gguf compile: -8% instructions.
…ne site processFunction asked, for every function in every patchInline round, whether the caller is too heavy to receive auto-inlined bodies: a full body-cost walk plus a call-graph cycle search. Most bodies hold no auto-inline site, so the answer was never used. The site collection now runs first; the check runs only when it found an auto-call site, and a heavy caller collects again without them. Under log_optimization the check stays ahead of the collection, so the over-budget log lines do not change. dasllama_gguf: caller checks 0.93 s -> 0.24 s, cycle-search bodies walked 93k -> 25k.
buildAccessFlags ran the full symbol-use pass on every rebuild: clear every use flag of the program, then propagate use from every exported and init function of every module in the library. It rebuilds after each optimization or inline round that changed the AST, so a big program walks its whole library hundreds of times per module. The side-effect pass reads only the module's use-edges, and no pass between inference and the module's final symbol-use pass reads the use flags; collectUseLists refreshes the edges alone. examples/dasLLAMA/run.das: symbol use inside the access rebuilds 5.1 s -> 1.1 s, compile 42.8 s -> 39.1 s user.
aleksisch
marked this pull request as draft
December 5, 2026 07:37
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ABI / rebuild: AST node layout changes (
gc_node48 -> 40 bytes,ExpressionlosesprintFlags,Programgains a flag), serializer version 312,ExprPrintFlags/Expression.printFlags/ast_print_flagsleave the das API. External modules rebuild. #nightlyWhy
Compiling
examples/dasLLAMA/run.das(17.8k functions, ~100 modules) spends its time in work that grows with the size of the library rather than with the code being compiled: name and alias lookups that walk every module or every global, and analysis passes that recompute whole-module results after changes that did not touch them. Its peak memory is mostly AST nodes, each carrying 16 bytes nothing needs.What changes
Inference:
Optimizer and inliner:
checkSideEffects) are recomputed only after the AST changed, like the access flags.buildAccessFlagsrefreshes only the module's use-edges (collectUseLists) instead of re-running library-wide symbol-use marking on every rebuild; nothing between inference and the final symbol-use pass reads the use flags.Memory:
gc_node:gc_idbecomes 32-bit besidegc_magic; every AST node is 8 bytes smaller (the global counter stays 64-bit).Expression.printFlagsis gone; the bracket decision lives in a side table,ExprBracketLevelsinast_boost, built by the AOT emitters andast_printbefore they emit.Results
Whole set, last four commits (5-8), user CPU time on an idle machine, average of two runs,
-compile-only -no-module-cache:examples/dasLLAMA/run.das(17.8k functions)dasllama_vulkan_classesdasllama_math_genPer commit:
run.das, one P-coregc_nodepackingrun.dasprintFlagsExpressionrun.dasdasllama_vulkan_classesdasllama_ggufdasllama_ggufrun.dasRows 1, 5 and 6 were measured on a loaded machine (absolute seconds there run several times higher than idle); the ratios hold.
Observable behavior
ast_printno longer brackets every operator:return x + 1,++y,b += f(...)(golden text intests/daslib/test_ast_print.das). AOT C++ output is unchanged.Where to look
src/ast/ast_infer_type.h,ast_infer_type_function.cpp,ast_infer_type_helper.cpp- the per-pass name index, the alias-global list.src/ast/ast_const_folding.cpp(checkSideEffects),src/ast/ast_unused.cpp+ast_export.cpp(collectUseLists),src/ast/ast_inline.cpp(callerTooHeavy).include/daScript/misc/gc_node.h,src/misc/gc_node.cpp- the packed id and its sizestatic_assert.daslib/ast_boost.das(ExprBracketLevels,new_bracket_levels/delete_bracket_levels/no_bracket),daslib/aot_cpp.das,daslib/aot_standalone.das,daslib/ast_print.das.Details
gc_nodepacking, theprintFlagsremoval, then the alias-global list, the side-effect cache, the lazy heavy-caller check and the use-edge refresh.ExprBracketLevelsis created and freed only through theast_boosthelpers, so the module's own AOT stub carries its constructor, methods and finalizer; anew/deletein the caller module left them out of the stub and failed the AOT link (50101).astChanged().log_optimizationthe inliner keeps its heavy-caller check ahead of the site collection, so its log lines do not change.tests/cuda/test_cuda_emit.das/test_cuda_oracle.das: NVRTC on this card cannot resolve__dp4a, the same on master.docs/digestreports drift already on master; this PR adds only its own digest lines.