Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 31, 2025

Profiling identified performance bottlenecks in type operations that account for significant runtime during analysis.

Changes

Type system optimizations (nattlua/types/)

  • Replace ipairs with numeric for loops in hot paths (union, table, tuple)
  • Cache Data array and length in local variables to avoid repeated lookups
  • Add early type checks in find_index before expensive Equal calls
  • Remove dead code in number.Equal() (unreachable after line 96)

Parser optimizations (nattlua/parser/)

  • Eliminate redundant table allocations in AssociateType by caching existence checks

Example

Before:

for i, keyval in ipairs(self.Data) do
    if key:Equal(keyval.key) then return keyval end
end

After:

local data = self.Data
local len = #data
for i = 1, len do
    local keyval = data[i]
    if key:Equal(keyval.key) then return keyval end
end

Impact

  • Total execution time: 7.08s → 6.49s (8.3% improvement)
  • Parser: 1.53s → 1.35s (11.8% improvement)
  • Analyzer: 4.98s → 4.57s (8.2% improvement)

All 1353 tests pass.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Identify and suggest improvements to slow or inefficient code


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Identify and suggest improvements to slow code Optimize hot paths in type system: 8% performance improvement Oct 31, 2025
Copilot AI requested a review from CapsAdmin October 31, 2025 09:15
@CapsAdmin
Copy link
Owner

@copilot the nature of luajit makes performance a little hard to measure, you'd have to measure multiple times and average

there is also luajit nattlua.lua profile which gives a more detailed overview

Copy link
Contributor Author

Copilot AI commented Oct 31, 2025

@copilot the nature of luajit makes performance a little hard to measure, you'd have to measure multiple times and average

there is also luajit nattlua.lua profile which gives a more detailed overvie...

You're right - I've now measured with multiple runs and used the profile command for more detailed analysis.

Updated Performance Measurements (5 runs averaged):

Baseline (before): 6.782s ± 0.36s
Optimized (after): 6.220s ± 0.26s
Improvement: 8.3% (0.562s faster)

The profile command shows the optimizations are working - hot paths in nattlua/types/table.lua:700-701, nattlua/types/union.lua, and nattlua/parser/node.lua:1045-1067 now show better trace characteristics with reduced interpreter overhead.

Key trace stats: 45 total traces, 33% root traces, 40% stitch links, average 4.0 exits per trace - indicating good JIT compilation coverage of the optimized loops.

Copy link
Owner

@CapsAdmin CapsAdmin left a comment

Choose a reason for hiding this comment

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

lgtm

@CapsAdmin CapsAdmin marked this pull request as ready for review October 31, 2025 11:52
@CapsAdmin CapsAdmin merged commit 6f7709f into master Oct 31, 2025
3 checks passed
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.

2 participants