Skip to content

Conversation

soutaro
Copy link
Member

@soutaro soutaro commented Sep 2, 2025

This is related to the RBS file parsing performance degradation.

The RBS file parsing in rbs-4.0 (dev) is ~5x slower than rbs-3.9, based on the core/**/*.rbs files, especially for smaller files.

https://docs.google.com/spreadsheets/d/1dQBGIC1_zWco6c5OHH5VunP8ZuZLzwaMDB-U31OgUAc/edit?gid=0#gid=0

I implemented minor changes to improve the parsing performance, reusing empty array and hash objects. The changes improved the parsing performance slightly, but it still clearly slower than rbs-3.9.

Add prepare_bench task
`bundle exec ruby benchmarks.rb core/**/*.rbs`
This is a prototype which doesn't `munmap` the heap. Introducing parser class to manage the allocators and changing the parsing methods to instance methods should allow releasing the heap.
@soutaro
Copy link
Member Author

soutaro commented Sep 12, 2025

@amomchilov
Copy link
Contributor

amomchilov commented Sep 12, 2025

Another thought:

How much time do we spend computing assertions? Should we disable them in "release" mode?

Currently, rbs_assert() is just a function that's never disabled:

void rbs_assert(bool condition, const char *fmt, ...) {
if (condition) {
return;
}
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
va_end(args);
fprintf(stderr, "\n");
exit(EXIT_FAILURE);
}

Perhaps we should rename the function to rbs_assert_impl(), and create an #define rbs_assert() macro that calls it only if we're in debug mode.

For comparison, C's standard library's assert.h, makes assert() a no-op if you #define NDEBUG

@amomchilov
Copy link
Contributor

Another thought: our extconf.rb doesn't specify an optimization level. We disable optimizations (-O0) if DEBUG is defined:

append_cflags ['-O0', '-g'] if ENV['DEBUG']

But we never specify -O3 if we're in a "release" mode

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