Todd Sundsted
toddsundsted@epiktistes.com
Better dead than bored.
Introductionepiktistes.com/introduction
GitHubgithub.com/toddsundsted/ktistec
Pronounshe/him
🌎Sector 001

it's interesting to see what scans show up in the logs:

2025-01-24 16:24:11 UTC 404 GET /.env 1.16ms
2025-01-24 16:24:11 UTC 404 GET /.env 563.87µs
2025-01-24 16:24:14 UTC 404 GET /.aws/credentials 601.43µs
2025-01-24 16:24:14 UTC 404 GET /.aws/credentials 498.43µs
2025-01-24 16:24:16 UTC 404 GET /.env.example 609.78µs
2025-01-24 16:24:16 UTC 404 GET /.env.example 544.13µs
2025-01-24 16:24:18 UTC 404 GET /.env.production 798.14µs
2025-01-24 16:24:19 UTC 404 GET /admin/.env 628.06µs
2025-01-24 16:24:23 UTC 404 GET /api/.env 906.66µs
2025-01-24 16:24:25 UTC 404 GET /app/.env 574.45µs
2025-01-24 16:24:27 UTC 404 GET /app_dev.php/_profiler/open?file=app/config/parameters.yml 537.69µs
2025-01-24 16:24:33 UTC 404 GET /app_dev.php/_profiler/phpinfo 841.8µs
2025-01-24 16:24:35 UTC 404 GET /backend/.env 513.92µs
2025-01-24 16:24:36 UTC 404 GET /core/.env 661.94µs
2025-01-24 16:24:38 UTC 404 GET /credentials 649.68µs
2025-01-24 16:24:40 UTC 404 GET /crm/.env 480.42µs
2025-01-24 16:24:43 UTC 404 GET /demo/.env 579.16µs
2025-01-24 16:24:49 UTC 404 GET /info/ 614.09µs
2025-01-24 16:24:51 UTC 404 GET /infos/ 705.33µs
2025-01-24 16:24:54 UTC 404 GET /pinfo.php 489.59µs
2025-01-24 16:24:58 UTC 404 GET /vendor/.env 780.1µs

this reminds me that i have to make responding to those requests much much slower...

#ktistec #security #todo

If you're running an instance of Ktistec and want to see what other ActivityPub instances are sending you, turn on JSON-LD processing debug logging.

  1. Go the the /system URL.
  2. Find the ktistec.json_ld setting.
  3. Select "Debug" and save.

Ktistec will dump received activities to the log, after the activity has been parsed into JSON but before JSON-LD expansion.

2025-01-22 14:53:17 UTC 409 POST /actors/toddsundsted/inbox 4.29ms
2025-01-22T14:53:17.597172Z  DEBUG - ktistec.json_ld: {"@context" => ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
"id" => "https://random.site/users/FooBar#delete", "type" => "Delete", "actor" => "https://random.site/users/FooBar", "object" => "https://random.site/users/FooBar", "to" => ["https://www.w3.org/ns/activitystreams#Public"], 
"signature" => {"type" => "RsaSignature2017", "creator" => "https://random.site/users/FooBar#main-key", "created" => "2025-01-22T14:52:40Z", "signatureValue" => "01234567890abcdefghijklmnopqrstuvwxyz=="}}

Answer to a FAQ:
The server returns HTTP status code 409 ("Conflict") if it has already received an activity.

#ktistec #fediverse #activitypub

Finally published a library I've wanted for a long time: a Crystal type for dealing with both calendar and monotonic durations in the same object.

github.com/jgaskins/duration

#Crystal #CrystalLanguage

Crystal is fast because methods are monomorphized at compile time. In simple terms, that means that at compile time, a polymorphic method is replaced by one or more type-specific instantiations of that method. The following polymorphic code...

def plus(x, y)
  x + y
end

...is effectively replaced by two methods—one that does integer addition if called with two integers, and one that does string concatenation if called with two strings.

This extends to inherited methods, which are implicitly also passed self. You can see this in action if you dump and inspect the symbols in a compiled program:

class FooBar
  def self.foo
    puts "#{self}.foo"
  end

  def bar
    puts "#{self}.bar"
  end
end

FooBar.foo
FooBar.new.bar

class Quux < FooBar
end

Quux.foo
Quux.new.bar

Dumping the symbols, you see multiple instantiations of the methods foo and bar:

...
_*FooBar#bar:Nil
_*FooBar::foo:Nil
_*FooBar@Object::to_s<String::Builder>:Nil
_*FooBar@Reference#to_s<String::Builder>:Nil
_*FooBar@Reference::new:FooBar
_*Quux@FooBar#bar:Nil
_*Quux@FooBar::foo:Nil
_*Quux@Object::to_s<String::Builder>:Nil
_*Quux@Reference#to_s<String::Builder>:Nil
_*Quux@Reference::new:Quux
...

The optimizer in release builds is pretty good at cleaning up the obvious duplication. But during my optimization work on Ktistec, I found that a lot of duplicate code shows up anyway.

Most pernicious are weighty methods that don't depend on class or instance state (don't make explicit or implicit reference to self). As I blogged about earlier, this commit replaced calls to the inherited method map on subclasses with calls to the method map defined on the base class and reduced the executable size by ~5.8%. The code was identical and the optimizer could remove the unused duplicates.

So, as a general rule, if you intend to use inheritance, put utility code that doesn't reference the state or the methods on the class or instance in an adjacent utility class—as I eventually did with this commit.

(The full thread starts here.)

#ktistec #crystallang #optimization

Release v2.4.5 of Ktistec

Ktistec release v2.4.5 rolls out the build time and executable size optimizations I've been blogging about here. It also fixes a few small bugs.

Fixed

  • Handle @-mentions with hosts in new posts.
  • Handle HEAD requests for pages with pretty URLs.
  • Destroy session after running scripts.

Changed

  • Delete old authenticated sessions.

I've started a branch full of query optimizations. My general rule—as highlighted in the server logs—is if a query takes longer than 50msec, it takes too long. It's time to address some problems...

#ktistec #fediverse #activitypub #crystallang

The Ktistec executable is now ~24.7% smaller and build times are 28% faster.

I've been blogging about optimizations here, here, and here. This is the summary of the final outcome, with links to commits for the curious. I have one more post planned with a summary of my thoughts.

Here's my approach. Use nm to dump the symbols in a release build executable and then look for things that seem redundant. The first change and associated post below is a great example of what I mean—my original implementation led to the specialization of the #== method for every pairwise combination of model classes even though the result of the comparison was just false.

This might seem like a strange approach if you come from a compiled language where you mostly write all of the code yourself or invoke generics explicitly, but Crystal takes your code and does that for you. And it's not always obvious up front (to me, at least) what the final cost will be.

I've include counts of the lines added/removed because the point of this whole post is to say if you measure first and then optimize, a small change can have a big impact.

Here are the changes:

  • Specialize model #==. (+7 -5)
    I talked about this here but didn't have the commit to link to. This change results in a large reduction in executable size on regular builds (~4.0%) and a small difference on release builds (~0.2%).
  • Remove conversion to Hash. (+2 -2)
    This commit eliminates specialization of methods like __for_internal_use_only that get passed both named tuples and hashes by going all in with named tuples. It also eliminates instantiations of the Hash generic type itself for these cases. Reduces executable size by ~2.2%.
  • Eliminate duplicate code in the executable. (+3 -3)
    This small change reduces the size of the executable by a further ~0.4% by eliminating redundant definitions of __for_internal_use_only entirely.
  • Make InstanceMethods instance methods. (+1 -5)
    This was a goofy design I picked up somewhere. It's unnecessary. Changing this saves ~0.2% on release build executable size.
  • Move the code for digging through JSON-LD. (+246 -281)
    It looks like a lot of lines of code changed here, but the large numbers are the result of moving code line-by-line from an included module to a utility class. Invoking these as methods on the utility class rather than as instance methods on each including class reduces the executable size by ~0.5%.
  • Use map from base ActivityPub model classes. (+10 -2)
    map is a class method defined on each ActivityPub base model class. Each definition maps JSON-LD to a hash that is used to instantiate the class. Class methods defined on a base class are available on subclasses, as well. Calling the method on the subclass results in a copy of the method. This change reduces the executable size by ~5.8%.
  • Move map into helper. (+104 -88)
    The map method does not depend on class/instance state. This change ensures that the mapping code is not duplicated even if a subclass's map method is accidentally again called. It looks like a lot of changes but this commit is mostly reorganization. It reduces executable size by ~0.4%.
  • Replace classes with aliases. (+62 -148)
    Implementing ActivityPub's vocabulary with discrete model classes is expensive because every model class comes with machinery for type-specific CRUD operations. Enumerate aliases on each base model class (e.g. a "Service" is an "Actor"). This change reduces executable size by ~16.9%.

I'm off to optimize some queries now...

#ktistec #crystallang

Serdar's post on Twitter saying:
Great news everyone

I've updated the Kemal Crystalkemal Cookbook with more recipes (Cookies, Databases, Redis e.g)

What else would you like to see in Kemal Cookbook?

Serdar updated the #crystalkemal cookbook with more recipes (i.e. #Cookies, #Databases, #redis ).

If you're looking for a #sinatra like framework for @CrystalLanguage, then #kemalcr is the best way to go.

#CrystalLang #CrystalLanguage#kemal

Happy New Year, happy new release! 🎇
1.15.0 is out with a new, efficient event loop, support for MinGW-W64 and MSYS2, improvements for BSD platforms, and many more features.
Watch out for the formatter changes, they'll likely affect your codebase!

crystal-lang.org/2025/01/09/1.

@jayvii i just discovered your introduction page. i liked it so much i copied the idea!

I've been on the Fediverse since January 2017. I initially ran a single-user instance of Mastodon. In March 2020 I started to write Ktistec, my own implementation of an ActivityPub server in Crystal (a language with the ergonomics of Ruby but the speed of Go) because I wanted something more supportive of writing. This #introduction was written and published on Epiktistes, my Ktistec instance.

I'm an Engineer by training but now I run teams for companies in climate-tech.

I love #music, #sciencefiction and #fantasy literature (yes, I'm an R. A. Lafferty fan), attend fan conventions like #worldcon and #dragoncon, and do regular #weightlifting. I am also learning to play the #bagpipes, and I'm (re)learning #japanese.