Repository navigation
Performance optimizations and release 5.1.1 - #23
Merged
Merged
Conversation
- Replace per-request lookahead Regexp compilation in RequestPathIntrospection#remove_current_segment with UTF-8-safe byte-indexed substring search (with character-index fallback for multi-slash segments) - Call service.__send__(:find, ...) directly in ResourceService#find, replace ActiveSupport delegate wrappers with lightweight controller readers, and reuse lazy SingletonSpecification#build_method_name - Fast-path Specification option validation and default foreign_key derivation, and add lazy plural_name / params_method_name helpers reused by #resources_name and #resource_params - Precompute class-level plural_route_name in resources_controller_for, read name_prefix once per NamedRouteHelper dispatch, guard empty enclosing/args splats, and preserve eql? enclosing-resource filtering - Reduce redundant params lookups in ResourceMethods, forward anonymous blocks in #new_resource, and simplify Helper#form_for_resource_options - Add regression specs covering all optimized paths and edge cases, update CHANGELOG, and bump version to 5.1.1 Co-authored-by: Antigravity (Gemini 4) <antigravity@google.com>
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.
Summary
Follow-up non-invasive performance optimizations across path introspection, resource services, specifications, named route helpers, and controller helpers, releasing 5.1.1.
Key Changes
RequestPathIntrospection#remove_current_segment): Replaced per-request lookaheadRegexpcompilation with UTF-8-safe byte-indexed substring search (byterindex+byteslice), with a character-index fallback for segments containing/. Preserves fresh mutable return strings and original encoding.ResourceService/SingletonResourceService):service.__send__(:find, ...)directly inResourceService#findinstead of falling back throughsuper→method_missing.delegatewrappers with directcontrollerreader methods (preserving subclass overrides on both proxy methods and#controller).SingletonSpecification#build_method_nameinSingletonResourceService#new.Specification/SingletonSpecification):options.assert_valid_keys(...)varargs allocation with a frozenVALID_OPTION_KEYScheck.foreign_keyfor simple snake_case names.plural_name(reused as a fresh mutable copy in#resources_name) and lazyparams_method_name(reused in#resource_paramswhen#resource_nameis not overridden).NamedRouteHelper):plural_route_namewith an immutableplural_route_name_sourcesnapshot (invalidated on class/instance overrides or in-place mutation).name_prefixonce per helper dispatch, guarded emptyencl/args/ single-elementenclsplats to avoid unnecessaryconcatarrayallocations, and preservedeql?filtering semantics for enclosing route helpers.ResourceMethods/Helper):paramslookups in#find_resource,#new_resource, and#destroy_resource, skipped duplicate param key lookup in#new_resource, forwarded anonymous&blocks, and removed.tapfromHelper#form_for_resource_options.CHANGELOGand bumpedResourcesController::VERSIONto5.1.1.Benchmark Highlights (Ruby 4.0.10 +YJIT, Rails 8.1.4)
remove_current_segment: 11–13× faster, -14 to -15 allocs/opresources_name(fresh controller): ~16× faster, -5 allocs/opResourceService#find: ~3.3× faster, -1 alloc/opSingletonResourceService#new: ~2.3× faster, -1 alloc/opnew_resource(empty params): ~1.3× fasterVerification
bundle exec rspec: 723 examples, 0 failures (22 new regression specs covering multibyte UTF-8 paths, overlapping multi-slash segments, duck-typed specifications, proxy overrides,eql?filtering, mutability/value invariants, androute_nameoverrides).