From a2634ec883af36c67cbcb37fb4ef3ee02169567c Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 27 Sep 2026 19:10:03 +0000 Subject: [PATCH] Document the cost of require 'facets' Measured on Ruby 3.3.6, Linux, without Bootsnap: require 'facets' (the core library only) adds about 35 ms of load time (median of 20 runs) and 1.8 MB of resident memory, loading 448 files that define about 858 methods. No single file costs more than about 1.3 ms; the time is spread evenly across many small files. The guide's "Load what fits" section and the README's core-collection paragraph now say so, noting that it covers the core library only and that numbers vary by machine. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01E2Njj4j1r9twkVcXsMySLW --- README.md | 2 +- docs/_src/learn.erb | 2 +- docs/learn.html | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a5c8566b..571af288 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ require 'facets' #=> 2.0 ``` -`require 'facets'` loads the broadly useful **core** extensions. Some specialized core extensions are opt-in; require their method file directly. To load Facets extensions to a Ruby standard library, require that library through Facets: +`require 'facets'` loads the broadly useful **core** extensions: roughly 860 methods from 448 files, adding about 35 ms of load time and 2 MB of memory (Ruby 3.3, Linux). Some specialized core extensions are opt-in; require their method file directly. To load Facets extensions to a Ruby standard library, require that library through Facets: ```ruby require 'facets/ostruct' diff --git a/docs/_src/learn.erb b/docs/_src/learn.erb index c80de573..0e92a776 100644 --- a/docs/_src/learn.erb +++ b/docs/_src/learn.erb @@ -8,7 +8,7 @@ require 'facets/array/to_ranges' require 'facets/string' # Most core extensions -require 'facets'

Standard library extensions are separate from the core collection. Require each one explicitly. For example, require 'facets/ostruct' loads Ruby's ostruct and the Facets additions for it.

Using Ruby 3.5+? Add the ostruct gem separately if you use Facets' OpenStruct extensions. Ruby no longer includes it as a default gem.
+require 'facets'

The core collection is light. require 'facets' adds about 35 ms of load time and 2 MB of memory, loading roughly 860 methods from 448 small files. That covers the core library only; standard library extensions load only when you require them. (Measured with Ruby 3.3 on Linux; your numbers will vary.)

Standard library extensions are separate from the core collection. Require each one explicitly. For example, require 'facets/ostruct' loads Ruby's ostruct and the Facets additions for it.

Using Ruby 3.5+? Add the ostruct gem separately if you use Facets' OpenStruct extensions. Ruby no longer includes it as a default gem.

03 / SEE IT WORK

A few useful facets

These examples use methods present in the 3.2 release.

RUBY
require 'facets/array/to_ranges'
 [1, 2, 3, 6, 7].to_ranges
 #=> [1..3, 6..7]
diff --git a/docs/learn.html b/docs/learn.html
index 85c3c54c..07ad7ee2 100644
--- a/docs/learn.html
+++ b/docs/learn.html
@@ -35,7 +35,7 @@
 require 'facets/string'
 
 # Most core extensions
-require 'facets'

Standard library extensions are separate from the core collection. Require each one explicitly. For example, require 'facets/ostruct' loads Ruby's ostruct and the Facets additions for it.

Using Ruby 3.5+? Add the ostruct gem separately if you use Facets' OpenStruct extensions. Ruby no longer includes it as a default gem.
+require 'facets'

The core collection is light. require 'facets' adds about 35 ms of load time and 2 MB of memory, loading roughly 860 methods from 448 small files. That covers the core library only; standard library extensions load only when you require them. (Measured with Ruby 3.3 on Linux; your numbers will vary.)

Standard library extensions are separate from the core collection. Require each one explicitly. For example, require 'facets/ostruct' loads Ruby's ostruct and the Facets additions for it.

Using Ruby 3.5+? Add the ostruct gem separately if you use Facets' OpenStruct extensions. Ruby no longer includes it as a default gem.

03 / SEE IT WORK

A few useful facets

These examples use methods present in the 3.2 release.

RUBY
require 'facets/array/to_ranges'
 [1, 2, 3, 6, 7].to_ranges
 #=> [1..3, 6..7]