#Lectern Caching Discussion

1 messages · Page 1 of 1 (latest)

neon dock
#

Working on some naive lectern slot caching that should fix some server killing cases when automating in/out of the lectern. Not everything can be optimized as neoforge doesn't provide common mod interfaces to fully solve it, but improvements for insertions can easily be optimized completely away.

Current changes:

  1. Caches the list of slots for an item/empty slot when an item is inserted
  2. Uses the list of slots on subsequent inserts, checks that the item in that slot is still the same item, then fills those slots with that item until there are no more stacks left, or there is no more room.
  3. If there is still part of an item remaining, it falls back to the empty slot list and inserts there.
  4. If there are no empty slots remaining/in the cache, it falls back to the current behavior of iterating across the inventory looking for valid spots to insert the item.

The pros:

  • Inserting an item a second time is immediate as long as there is room or an empty slot is available
  • Inter-mod export can also be optimized, wixies and starbuncles benefit, but other modded extractions would not.

Cons:

  • Items will insert at 'random' places in the chest if it falls back to an empty slot, not consistent with expected behavior like how it works today.
  • If inventory is completely full, the fallback behavior of checking everything all the time comes back.
  • Manipulation of the inventory outside of the lectern will exacterbate the randomness problem as there is no way to know that the inventories of a monitored inventory have changed without other performance costs.
#

@surreal rose @nimble latch ^ I know you guys had requested in the past ways to go the opposite direction by forcing the lectern to be more organized. My philosophy and play style is more that chests are just disks and I use the lectern because I dont want to look at them. curious what you guys think and if some consideration needs to be made, or some ability to disable this caching behavior entirely?

surreal rose
#

hm. So, I tend to use the lectern in a few distinct ways. First is the intended use of aggregating your storage room into a single interface, which I usually have something like Limited Barrels holding items I want to access frequently, and then the rest is just bulk storage that I don't organize

My second method is in smaller networks with highly specified jobs, which... I don't think this should really impact?

Now, I suppose the question would be, this still follows the item frame filtering, yeah?

neon dock
#

Yep

#

The caching is per inventory, but inventory priority still applies

solid hound
#

just some thoughts on the internals, could you store an open slot (or an ordered list of open slots) and try to swap any inserts into the first open slot?

#

which would be 1 extra extract

#

and a check to make sure that the slot is actually open

#

and a linear search otherwise lol

#

probably not the best idea for people who muck around with the backing inventories

#

which is the whole reason swapping to free slots would be helpful in the first place

neon dock
#

I guess empty slots could be stored as a minheap?

solid hound
#

i think the problem is that invalidation and search of free-ness would be expensive

neon dock
#

It’s a bit unavoidable though, if you cache empty slots at all you still have the case where someone extracts a full stack and that slot isn’t cached and is therefore skipped

solid hound
#

but otherwise its pretty meh

#

think youll end up doing a lot of linear searches

neon dock
#

Yeah, this is all designed assuming you don’t care what the backed inventory actually looks like

solid hound
#

yeah but swapping to first free is for people who do care

neon dock
#

It’s optimistic caching assuming it wont be manipulated externally

solid hound
#

so pretty incompatible

neon dock
#

Ye

solid hound
#

actually there are slot listeners arent there

#

but lets not

#

probably way more expensive than its worth

#

function call to do hashing on every insert/extract sounds bad

neon dock
#

slot listeners only apply to containers/GUI for players. there is not concept of subscribing to changes in an inventory, you can only know that it has become invalid and thus need to rebuild your entire cache each time that happens

solid hound
#

also i think it would be worth seeing at what number of slots caching is actually helpful

#

i somewhat doubt that its better at 27

neon dock
#

yeah, I think it should be enabled when your lectern has a certain number of slots

solid hound
#

but the cache is also per inventory yeah?

neon dock
#

its just objectively worse in the cases where the inventory is full or the cache misses, so the smaller the inventory the more penalty you pay for that

#

it is, but the lectern combined inv wrapper has a total slot count

solid hound
#

im just thinking, 1000x 9 slot inventories (e.g. droppers) would probably not be a great candidate for per inventory caching

#

even though it is 9000 slots

#

or more egregiously 1000 decorated pots

#

not sure if they even have a real Container though

neon dock
#

thats not a realistic use case, if you connect your lectern to that many droppers by hand then you deserve to be at 4 tps

solid hound
#

yeah im just saying its worth asking at what number of slots is it bad

neon dock
#

the server killing case is when people connect their lectern to a massive wall of drawers

solid hound
#

because im doubting 27

#

i feel like even at 27 not caching could be faster

#

54 is a maybe

#

and if 54 is worse with caching then caching isnt worth doing at all, probably

surreal rose
#

now, how about when a lectern is linked to, say, a Storage Controller? Does it see that as a single inventory?

neon dock
#

yes

#

which is where you really benefit from

#

or a create vault

surreal rose
#

my storage system last server was a storage controller linked to limited barrels, and 5 create vaults

neon dock
#

ironically, you only benefit when you are abusing another mods giant storage proxy lol, not the actual vanilla chest case

solid hound
#

yeah which is why im concerned about inventories with smaller slot sizes

#

like 27

#

and 54

#

which are the most common slot sizes

neon dock
#

thats an easy conditional to just not bother doing it for them

solid hound
#

just saying we should measure!

#

it could still be better

#

im just not sure

#

because ive got no numbers

#

i think its pretty obvious that we shouldnt bother doing it for 9 or below

neon dock
#

the lectern could merge all non-filter scroll inventories into an inv wrapper and treat them all as one big inventory

solid hound
#

could be worthwhile but im scared of item voiding

neon dock
#

accursed capability validations

solid hound
#

fairly sure the item void i reported a while ago still isnt fixed

#

ill take a look at it some day

#

this one #api-development message

#

i definitely think a migration to BlockCapabilityCache is overdue

#

and i dont think doing so will break any addons

#

likeliest to break is ars polymorphia, which im ok to fix

#

anyways its snooze time

nimble latch
#

I'm like xacris. Two main uses are standard storage room: drawer network and a few dozen repositories. And then odd-use automation. Which I've got a few ideas for building, but haven't yet on the server

#
  1. Essence automation up in the power crystal. I've got 3 lectern nets up there. Each pulling from a repo under the lectern, inserting into 15 gem chambers, and about 20 (plan is 40-60) essence chambers. The last net is connected to a single pedestal that feeds the volcanic that runs everything. I might add more to that, or link instead to a couple hoppers pointed at pedestals instead
#
  1. Automation output. My plan here was to have a second full base lectern network that handled output to automation. So instead of wixies seeing my entire base inventory, they'd instead see only about 30-60 single slot decorated pots.

Back at main storage, a starby or two would be using mimic filters to output from primary to this output secondary network

#

Genuinely don't know if that will be better or worse than pulling directly from main storage. That's something I want to test

#

The intent is to be better on the server, so I've got two starbies that see the whole of both networks, instead of 20 wixies and countless other outputs trying to pull from primary

#

My question with the initial ideas you posted. When you insert an item, it caches the existing slots, and all the empty slots for that item. So if I've got a few hundred items that are auto inserting, is that list for each item?

#

Would it make sense to have a specific block to be importing from for that to be the case? I can see a use case where a player says "the lectern auto pulls from an adjacent inventory" and so their base has something like an ender chest that they dump things into. So the list of auto-inserted items would be "whatever junk they find while exploring"

#

So having a different block like a caching import bus or something, where items that get pulled into the storage through that block would have the history, but not every random leather chest with thorns 2

neon dock
#

The list of slots is per item type, keyed by item not the item data, and one list of all empty slots since Air is just the item for empty slot, so the fallback would be: Check if there is a list for my item -> insert if the slots exist and are valid -> if not valid, try to find a slot where I can fit my item, use the fallback empty slots if I still havent inserted everything

#

And for non-stackables they will leverage the empty list immediately since there is no point trying to stack it on itself

nimble latch
#

Hmm
With that last part, how does that handle normally-non-stackables that become stackable because of other mods? Like drawers set for specific things, with larger stack sizes?

#

I don't actually know how that works, of course. I've just used it for things like botania mana tablets in drawers when they're full

neon dock
#

thats a good question, would depend how they implement it...

nimble latch
#

Normally they don't stack, but with stack size upgrades on things they might be "stackable"

#

Yeah no idea how they do it lol. Maybe it just looks like one stack, but it's still 20 individual slots.. no clue

#

Tangent.

The other day I'd had an idea about a storage block that could only be accessed by lectern. To ensure the list of items never changes without a lectern having handled the in/out. Would that help anything?

Though at the same time, there's nothing preventing a chest from belonging to multiple lectern networks

#

Mostly I'm just trying to be mindful of my own base impact on server performance. I want lots of automation, but without causing too much pain on the server

#

Redstone monitoring helps to reduce actual item movements that aren't needed, but at the same time, that's still a display case that needs to monitor the base inventory

#

I know my 1.16 base was laggy even without anything being produced, because of corporea monitoring everything. Even just loading my base caused a few issues where production would start running because it got loaded before my base did, so showed up as 0 quantity of that item before being fully loaded

neon dock
#

a block that only the lectern can interface with gives you AE2 performance but then other mods can't interact with it without going back to iteration, like hoppering ito it

nimble latch
#

The side thought on that would have been that it's a fake inventory block, that increases the internal lectern slot count, without actually being stored in that other block

#

But that's a whole other system then if lecterns have an internal storage

neon dock
#

and removing items from it is the same issue, you would need an export bus that you could then hopper out of as an intermediate since mods dont have a way to request an itemstack, they can only check a slot to determine for themselves if the item in that slot is what they wannt

nimble latch
#

Hmm. Makes sense. This whole thought came about when thinking about my automated enchanting apparatus. A way to request specific items from a lectern (enchanting apparatus ingredients)

#

But I suppose output is a separate discussion

neon dock
#

hard to know exactly wtf people are doing to destroy their servers when server owners just come in and say 'lectern slow' without a profile

#

or any idea as to what is actually being done

nimble latch
#

That's fair yeah. It's part of why I'm thinking of different ways to use the lectern on the server to try to get reference points for what works and doesn't

neon dock
#

at least on the ars servers the common theme has been anything to do with lectern + drawer wall

nimble latch
#

Unrelated, the other day I was trying to have a lectern with 4 chambers around it, so it would pull the output when it matched the linked storage filters. Apparently it only wants to pull from one at a time, so that's fine.

But the weird thing was that because of how it was checking for a match, it ended up basically freezing the chamber, it was at 100% (per data get) but never converted

neon dock
#

huh, thats weird

nimble latch
#

I eventually scrapped that plan anyway and went with just starbuncles to handle moving between networks. But it was just a weird observation

#

I had 3 amethyst that were in chambers and 2 of them had converted a few times, but the one that I assume was being pulled from never changed. And nothing was ever sent to the "storage" on that network (chest with source gem filter, next to the next lectern network)

#

And I prefer the new build I have, so not a big deal. Just random.

#

But off topic lol

#

So you said that for small slot size systems like this it (your plan above for caching) wouldn't really make much difference in performance? I guess with something like chambers linked as the storage, the slot is either going to be full, or air.

neon dock
#

shouldnt make a difference for small inventories no

nimble latch
#

Ok. It's one of the interesting applications of the lecterns that I want to play with more for automation ideas. Otherwise my current base storage plans are just a small drawer network for compression of ingots and then repositories for everything else

#

Though I was debating if I wanted to set up something like an occultism storage somewhere as deep storage for things like cobblestone. Maybe slap a mimic filter or something on it, so it only holds the items I want